NanoApe Loves Sequence Ⅱ

链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5806

题目:NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination!

In math class, NanoApe picked up sequences once again. He wrote down a sequence with   numbers and a number   on the paper.

Now he wants to know the number of continous subsequences of the sequence in such a manner that the   -th largest number in the subsequence is no less than   .

Note : The length of the subsequence must be no less than   .

题意:给一串数字,求所有长度大于k,第k大的数字大于等于m的字串个数

分析:这道题很巧妙的用了前缀和来保存从第一个数字到底n个数字里面大于m的数字的个数,之后再用尺取法遍历,记录结果。

题解:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

int pre[200010];
__int64 ans;
int n,m,k,temp;

int main()
{
	//freopen("in.txt","r",stdin);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ans=0;
		scanf("%d %d %d",&n,&m,&k);
		for(int i=1;i<=n;i++){
			scanf("%d",&temp);
			if(temp>=m)
				pre[i]=pre[i-1]+1;
			else
				pre[i]=pre[i-1];
		}
		int l,r;
		l=0,r=1;
		for(;l<n;l++){
			while(pre[r]-pre[l]<k&&r<=n)
				r++;
			if(pre[r]-pre[l]<k)break;
			ans+=n-r+1;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值