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;
}
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-5806 NanoApe Loves Sequence(尺取法)
- HDU - 5806 - NanoApe Loves Sequence Ⅱ 【思维尺取】
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- bestcoder #86 第三题 NanoApe Loves Sequence Ⅱ hdu 5806
- HDU-5806-NanoApe Loves Sequence Ⅱ-DP+队列维护
- HDU 5806 NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- 【HDU】5806 - NanoApe Loves Sequence Ⅱ(尺取法)
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
- hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)
- HDU 5806 NanoApe Loves Sequence Ⅱ(尺取)
- hdu 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806 NanoApe Loves Sequence Ⅱ (滑动窗口 或者 二分法)
- HDU 5806 NanoApe Loves Sequence
- HDU 5806 - NanoApe Loves Sequence Ⅱ (BestCoder Round #86)
- BestCoder Round #86 1003 &HDU 5806——NanoApe Loves Sequence Ⅱ
- HDU-5806-NanoApe Loves Sequence Ⅱ(水题)
- HDU 5806 · NanoApe Loves Sequence Ⅱ【尺取法】
- hdu 5806 NanoApe Loves Sequence Ⅱ 尺取法