#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int M=201000;
int n,m,k;
int a[M];
long long ans;
void solve()
{
int s=0,t=0,sum=0;
while(1)
{ // as+1~at-1<=as~at-1<m
while(t<n&&sum<k)//找到第一个满足条件的t 若as+1~at'成立 则t'>=t
{
sum+=a[t];
t++;
}
if(sum<k) break;
ans+=(n-t+1);// (s,t)可行 (s,t') t'>=t都可行
sum-=a[s++];
}
cout<<ans<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
ans=0;
cin>>n>>m>>k;
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
if(x>=m) //方便尺取
a[i]=1;
else
a[i]=0;
}
solve();
}
return 0;
}
hdu 5806尺取法运用
最新推荐文章于 2020-02-07 21:35:31 发布
本文介绍了一种解决特定区间计数问题的算法实现。通过使用滑动窗口的方法,在给定数组中寻找满足条件的子数组数量。适用于编程竞赛及算法面试等场景。
1145

被折叠的 条评论
为什么被折叠?



