hdu 5806 NanoApe Loves Sequence Ⅱ
2016-08-06 22:59
330 查看
题意:求满足第K大的数>=m的区间个数
解题思路:将这N个数>=m的标记为1,<m标记为0。
一个区间满足第k大的数>=m,即该区间的1的个数>=k.
解题思路:将这N个数>=m的标记为1,<m标记为0。
一个区间满足第k大的数>=m,即该区间的1的个数>=k.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int cnt[200000+10]; ll dp[100000+10]; int main() { int T; scanf("%d",&T); int n,m,k; ll ans; while(T--) { scanf("%d%d%d",&n,&m,&k); memset(cnt,0,sizeof(cnt)); int a; for(int i=0;i<n;i++) { scanf("%d",&a); if(a<m) cnt[i]=0; else cnt[i]=1; } ans=0; int num=0; int i,j=0; for(i=0;i<k;i++) if(cnt[i])num++; while(j<n) { while(i<n&&num<k) { if(cnt[i]) num++; i++; } if(i>=n&&num<k) break; ans+=n-i+1; ///因为区间内>=m的个数 >=k都满足 if(cnt[j]) ///当cnt[j]==1时,此时这个区间>=m的数小于k num--; /// 所以要找到下一个>=m的数。 j++; } printf("%I64d\n",ans); } return 0; }
相关文章推荐
- HDU-5806-NanoApeLovesSequenceⅡ(尺取法)
- (尺取法)HDU - 5806 NanoApe Loves Sequence Ⅱ
- HDU 5806:NanoApe Loves Sequence Ⅱ
- hdu_5806_NanoApe Loves Sequence Ⅱ(双指针)
- 二指针_____NanoApe Loves Sequence II(hdu 5806 BestCoder Round #86)
- 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 1003
- HDU 5806 - NanoApe Loves Sequence Ⅱ
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
- HDU 5806 NanoApe Loves Sequence Ⅱ two pointers
- HDU-5806 NanoApe Loves Sequence Ⅱ(two-pointer或二分)
- HDU 5806 NanoApe Loves Sequence Ⅱ
- Hdu-5806 NanoApe Loves Sequence(尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU-5806-NanoApe Loves Sequence Ⅱ-DP+队列维护
- HDU - 5806 - NanoApe Loves Sequence Ⅱ 【思维尺取】
- bestcoder #86 第三题 NanoApe Loves Sequence Ⅱ hdu 5806