NanoApe Loves Sequence Ⅱ HDU - 5806(尺取)

NanoApe Loves Sequence Ⅱ

题目链接:HDU - 5806
题意:给出一个数列,找出其中第k大数不小于m的连续子序列的个数;
很简单的一道题,读题时把样例的k,m颠倒了,卡了半天题意,,,

#include <bits/stdc++.h>
using namespace std;
const int maxn=200100;
int a[maxn];
int main(){
	int T;
	scanf("%d", &T);
	while(T--){
		int n, k, m;
		scanf("%d%d%d", &n, &m, &k);
		for(int i=0; i<n; i++){
			scanf("%d", &a[i]);
		}
		int cnt=0;
	   	long long ans=0;
		for(int i=0, j=0; i<n; i++){	
			while(cnt<k&&j<n){
				if(a[j]>=m) cnt++;
				j++;
			}
			if(cnt>=k) ans+=(n-j+1);
			if(a[i]>=m) cnt--;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/sirius_han/article/details/81005763