NanoApe Loves Sequence Ⅱ

原创 2016年08月30日 10:13:45
链接: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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

HDU 5806 NanoApe Loves Sequence Ⅱ(双指针)

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)Problem Descrip...

HDU 5806 NanoApe Loves Sequence Ⅱ (滑动窗口 或者 二分法)

NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (J...

HDU5806 NanoApe Loves Sequence Ⅱ BestCoder Round #86 two-pointer

NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (J...
  • kyoma
  • kyoma
  • 2016年08月09日 10:00
  • 240

hdu 5806 NanoApe Loves Sequence Ⅱ

比赛的时候真是该更冷静一些。

HUD-5806 NanoApe Loves Sequence Ⅱ(二分)

问题描述 退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 nn 的数列,他又根据心情写下了一个数 mm。 他想知道这个数列中...

hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)

NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (J...
  • acm_cxq
  • acm_cxq
  • 2016年08月06日 22:09
  • 372

hdu5806 NanoApe Loves Sequence Ⅱ 前缀和 + 二分

NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (J...

HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)

NanoApe Loves Sequence Ⅱ  题目链接:点我打开链接 Source BestCoder Round #86  题意:问你这个数列中有多少个区间里的第 k大的数不小于...

HDU 5806 NanoApe Loves Sequence Ⅱ尺取法

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意: 问题描述 退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒...

【杭电 5805 8.6 BC B NanoApe Loves Sequence】

NanoApe Loves SequenceProblem Description NanoApe, the Retired Dog, has returned back to prepare fo...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:NanoApe Loves Sequence Ⅱ
举报原因:
原因补充:

(最多只允许输入30个字)