HDU5806:NanoApe Loves Sequence Ⅱ(尺取法)

题目链接:HDU5806

题意:找出有多少个区间中第k大数不小于m.

分析:用尺取法可以搞定,CF以前有一道类似的题目.

 1 #include<cstdio>
 2 using namespace std;
 3 typedef long long ll;
 4 #define d\n I64d\n
 5 int T,n,m,K,num,r,a[200010];
 6 ll ans;
 7 int main()
 8 {
 9     scanf("%d",&T);
10     while (T--)
11     {
12         scanf("%d%d%d",&n,&m,&K);
13         for (int i=1;i<=n;i++) scanf("%d",&a[i]);
14         num=0;r=0;ans=0;
15         for (int i=1;i<=n;i++)
16         {
17             while (num<K&&r<n){r++;num+=(a[r]>=m);}
18             if (num<K) break;
19             ans+=n-r+1;
20             num-=(a[i]>=m);
21         }
22         printf("%d",ans);
23     }
24 }
View Code

 

posted @ 2016-08-07 11:34  遗风忘语  阅读(153)  评论(0编辑  收藏  举报