http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=721&pid=1003
尺取法,先找k个>=m的,定位到r指针。然后移动l,如果a[l]>=m,说明现在区间内不足k个,r指针向后移,补到k个,如果a[l]<m,r指针就不用变
#Code
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 200000 + 9;
int a[MAXN];
void solve()
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
long long ans = 0;
int r;
int t = 0;
for (r = 0; r < n; r++) {
if (a[r] >= m) t++;
if (t == k) break;
}
ans += (n - r);
for (int l = 1; l < n; l++) {
if (a[l - 1] >= m) {
t--;
r++;
for (;r < n; r++) {
if (a[r] >= m) t++;
if (t == k) break;
}
if (r >= n) break;
ans += (n - r);
} else {
ans += (n - r);
}
}
cout << ans << endl;
}
int main()
{
//freopen("in", "r", stdin);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
}