您的位置:首页 > 产品设计 > UI/UE

HDU 5806 NanoApe Loves Sequence Ⅱ

2016-08-07 20:12 351 查看
Problem Description

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 n numbers
and a number m on
the paper.

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

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

 

Input

The first line of the input contains an integer T,
denoting the number of test cases.

In each test case, the first line of the input contains three integers n,m,k.

The second line of the input contains n integers A1,A2,...,An,
denoting the elements of the sequence.

1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤109

 

Output

For each test case, print a line with one integer, denoting the answer.

 

Sample Input

1
7 4 2
4 2 7 7 6 5 1

 

Sample Output

18
m是确定的,所有的数就变成了0和1,然后循环一遍就可以了,原来这种方法叫two-pointer,从来都不知道。。#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
using namespace std;
typedef __int64 LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int T, n, m, k;
int a
, cnt;

int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d%d", &n, &m, &k);
rep(i, 1, n) scanf("%d", &a[i]);
LL ans = cnt = 0;
for (int i = 1, j = 1; i + k - 1 <= n; cnt -= a[i++] >= m)
{
for (; j <= n && (i + k - 1 > j || cnt < k); j++) cnt += a[j] >= m;
if (cnt >= k) ans += n - j + 2;
}
printf("%I64d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDU