HDU 5806 · NanoApe Loves Sequence Ⅱ【尺取法】
来源:互联网 发布:linux退出 编辑:程序博客网 时间:2024/05/24 22:44
【题意】
退休狗NanoApe,他准备重新参加国家高等教育入学考试!在数学科目上,他再次拾起数列(这个知识)。他在纸上写下了一个满足数字
注意:子序列的长度必须不小于
限制条件:
关键原文:
Now he wants to know the number of continous subsequences of the sequence in such a manner that the
【提炼】
给定一个数列,以及m,k值,求满足区间里第k大的数不小于m的区间数值的个数(即区间长)。
【分析】
因为要求出第k大的数满足某个条件,第一反应是分治法来处理;提到必须连续,进而想到尺取法,我们只要处理出大于等于m的区间前缀和,然后累加区间长就可以了。
具体做法是这样:
我们把大于等于m的数记为1,累加至k个,即满足所求条件,累加区间长即可。
Tips:由于要累加很多的区间长,这个值会爆int型,建议使用范围更大的long long型。(坑点)
【时间复杂度】
显然,
【代码】
/* coder: Tangent Chang date: 2017/5/14 A day is a miniature of eternity. by Emerson*/#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>using namespace std;typedef long long ll;int d[200000 + 5];int main() { int T; scanf("%d", &T); while (T--) { int n, k, m; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; ++i) { scanf("%d", &d[i]); } int s = 0, t = 0, cnt = 0; ll res = 0; while (s < n) { while (cnt < k && t < n) { cnt += (d[t++] >= m); } if (cnt == k) { res += n - t + 1; } cnt -= (d[s++] >= m); } printf("%lld\n", res); } return 0;}
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 Ⅱ(二分或尺取法)
- hdoj5806 NanoApe Loves Sequence Ⅱ(尺取法)
- NanoApe Loves Sequence Ⅱ(尺取法)
- hdu 5806 NanoApe Loves Sequence Ⅱ(乘法原理/尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU5806 NanoApe Loves Sequence Ⅱ(尺取法\two pointers)
- Java内存机制
- BZOJ 1008: [HNOI2008]越狱
- CodeForces
- 第19章 连续周期信号的频域分析
- linux下进入mysql数据库出现1045及2003错误,解决方法
- HDU 5806 · NanoApe Loves Sequence Ⅱ【尺取法】
- 第3章 编程问题 3.2节 1
- JAVA源码解析(2)-java.beans.FeatureDescriptor、
- python读取文本数据到矩阵(用于scikit-learn输入)
- 1120. Friend Numbers (20)
- String中substring方法内存泄漏问题
- Java wed 编码问题
- css伪劣的bug
- 【Java EE】--JavaServer Faces 02