HDU 5806 NanoApe Loves Sequence Ⅱ

将大于等于m的数改为1,其余的改为0。问题转变成了有多少个区间的区间和>=k。可以枚举起点,二分第一个终点 或者尺取法。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int T,n,m,k,a[maxn],sum[maxn]; int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k); sum[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>=m) a[i]=;
else a[i]=;
sum[i]=sum[i-]+a[i];
}
LL ans=; for(int i=;i<=n;i++)
{
int L=i,R=n,pos=-;
while(L<=R)
{
int mid=(L+R)/;
if(sum[mid]-sum[i-]>=k) pos=mid,R=mid-;
else L=mid+;
}
if(pos==-) continue;
ans=ans+n-pos+;
}
printf("%lld\n",ans);
}
return ;
}
上一篇:sql字符串查找大小写敏感相关


下一篇:.PIG File