Hdu-5806 NanoApe Loves Sequence(尺取法)
来源:互联网 发布:掌盟书城java下载 编辑:程序博客网 时间:2024/05/21 10:33
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 withn n numbers and a number m m on the paper.
Now he wants to know the number of continous subsequences of the sequence in such a manner that thek k-th largest number in the subsequence is no less than m m.
Note : The length of the subsequence must be no less thank k.
In math class, NanoApe picked up sequences once again. He wrote down a sequence with
Now he wants to know the number of continous subsequences of the sequence in such a manner that the
Note : The length of the subsequence must be no less than
In each test case, the first line of the input contains three integers
The second line of the input contains
17 4 24 2 7 7 6 5 1
18
题意:问数列中有多少区间满足区间第k大数不小于m。
分析:尺取法求出以每个下标结尾的所有区间个数。
#include<iostream>#include<string>#include<algorithm>#include<cstdlib>#include<cstdio>#include<set>#include<map>#include<vector>#include<cstring>#include<stack>#include<queue>#define INF 2147483640#define eps 1e-9#define N 200005#define MOD 1000000007typedef long long ll; using namespace std;int t,n,m,k,tot,a[N];int main(){scanf("%d",&t);for(int T = 1;T <= t;T++){ll ans = 0;int i,j,sum = 0,tot = 0;scanf("%d%d%d",&n,&m,&k);for(int i = 1;i <= n;i++) scanf("%d",&a[i]);for(j = 1;j <= n && sum != k;j++) {if(a[j] >= m) {sum++;i = j;}tot++;}if(sum != k){cout<<0<<endl;continue;}tot--,sum--;for(;i <= n;i++){tot++;if(a[i] >= m) sum++;while(sum >= k){if(a[i - tot + 1] >= m) sum--;tot--; }tot++;sum++;ans += i - tot + 1ll; }cout<<ans<<endl;}}
0 0
- 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 Ⅱ尺取法
- hdu 5806 NanoApe Loves Sequence Ⅱ 尺取法
- hdu 5806 NanoApe Loves Sequence Ⅱ(二分或尺取法)
- HDU 5806 · NanoApe Loves Sequence Ⅱ【尺取法】
- hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- hdoj5806 NanoApe Loves Sequence Ⅱ(尺取法)
- NanoApe Loves Sequence Ⅱ(尺取法)
- HDU 5806 NanoApe Loves Sequence
- poj2376 Cleaning Shifts
- LeetCode_283. Move Zeroes
- C++三种容器:list、vector和deque的区别
- HTML5之SVG 2D入门1—SVG(可缩放矢量图形)概述
- 深度增强学习(DQN)的各种改进(一)
- Hdu-5806 NanoApe Loves Sequence(尺取法)
- hibernate进二阶之项目中session的管理方式
- 线程小酌之理解线程池
- 对 laravel 中服务提供者(Provider)和 门面(Facades) 的理解
- 配置DispatcherServlet
- Java异常类
- dev&VC编译,运行,编译运行的快捷键~
- 熟悉android开发框架,关于Okhttp3的使用
- centos 自带mysql卸载时出现无法卸载情况