MYF

HDU 5806 NanoApe Loves Sequence

题目链接

HDU 5806

题目类型:滑动窗口模拟

题目来源:BestCoder Round #86

题目分析

题目大意

中文题面

解析

赛后发现这题完全用不到主席树什么的数据结构,直接滑动着跑就行了。。。

对于每一个数,先判断它是否大于等于m,算出来每一个点及其之前的值共有多少大于等于m的数,每次枚举左边端点,然后二分的查找右端点求长度再累加即可。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <iostream>
#include <deque>
#include <algorithm>
#define Memset(a,val) memset(a,val,sizeof(a))
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define rt(n) (i == n ? '\n' : ' ')
#define hi printf("Hi----------\n")
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("output.txt","w",stdout);
#define debug(x) cout<<"Debug : ---"<<x<<"---"<<endl;
#define debug2(x,y) cout<<"Debug : ---"<<x<<" , "<<y<<"---"<<endl;
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int maxn=200000+5;
const int mod=1000000007;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int a[maxn];
int main(){
int T;
scanf("%d",&T);
while (T--) {
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for (int i=1; i<=n; i++) {
scanf("%d",&a[i]);
if (a[i]>=m) a[i]=1;
else a[i]=0;
a[i] += a[i-1];
}
ll ans= 0;
for (int i=0; i<=n-k; i++) {
int pos = lower_bound(a+1, a+1+n, a[i]+k) - a;
ans += n - pos + 1;
}
cout<<ans<<endl;
}
}