2096: [Poi2010]Pilots
来源:互联网 发布:mac qq安卓显示mac在线 编辑:程序博客网 时间:2024/05/17 07:11
2096: [Poi2010]Pilots
Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 746 Solved: 382
[Submit][Status][Discuss]
Description
Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值。耍畸形一个人是不行的,于是他找到了你。
Input
输入:第一行两个有空格隔开的整数k(0<=k<=2000,000,000),n(1<=n<=3000,000),k代表Tz设定的最大值,n代表难度序列的长度。第二行为n个由空格隔开的整数ai(1<=ai<=2000,000,000),表示难度序列。
Output
输出:最大的字串长度。
Sample Input
3 9
5 1 3 5 8 6 6 9 10
5 1 3 5 8 6 6 9 10
Sample Output
4
(有两个子串的长度为4: 5, 8, 6, 6 和8, 6, 6, 9.最长子串的长度就是4)
(有两个子串的长度为4: 5, 8, 6, 6 和8, 6, 6, 9.最长子串的长度就是4)
HINT
Source
by poi
显然,,具有决策单调性(水经验。。。)
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<algorithm>#include<cmath>using namespace std;const int maxn = 3E6 + 30;int n,k,h1,t1,h2,t2,A[maxn],q1[maxn],q2[maxn];bool Judge(int R){if (h1 > t1 || h2 > t2) return 1;int Max = h1 <= t1?max(A[q1[h1]],A[R]):A[R];int Min = h2 <= t2?min(A[q2[h2]],A[R]):A[R];return Max - Min <= k;}void Insert(int R){while (h1 <= t1 && A[q1[t1]] <= A[R]) --t1;while (h2 <= t2 && A[q2[t2]] >= A[R]) --t2;q1[++t1] = q2[++t2] = R;}int getint(){char ch = getchar(); int ret = 0;while (ch < '0' || '9' < ch) ch = getchar();while ('0' <= ch && ch <= '9')ret = ret*10 + ch - '0',ch = getchar();return ret;}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifk = getint(); n = getint();for (int i = 1; i <= n; i++) A[i] = getint();int Ans,R; Ans = R = 0; h1 = h2 = 1;for (int i = 1; i <= n; i++){while (h1 <= t1 && q1[h1] < i) ++h1;while (h2 <= t2 && q2[h2] < i) ++h2;while (R < n && Judge(R + 1)) Insert(++R);Ans = max(Ans,R - i + 1);}cout << Ans;return 0;}
0 0
- [BZOJ 2096]Poi2010 Pilots
- BZOJ 2096: [Poi2010]Pilots
- BZOJ 2096 [Poi2010]Pilots
- [BZOJ 2096][Poi2010]Pilots
- 2096: [Poi2010]Pilots
- bzoj 2096: [Poi2010]Pilots
- BZOJ 2096([Poi2010]Pilots-单调队列-差值)
- BZOJ 2096 Poi2010 Pilots 单调队列
- BZOJ 2096: [Poi2010]Pilots|单调队列
- bzoj 2096: [Poi2010]Pilots 单调队列
- [BZOJ 2096][Poi2010]Pilots:单调队列
- 单调队列 BZOJ 2096 [Poi2010]Pilots
- BZOJ 2096: [Poi2010]Pilots 单调队列题解
- BZOJ 2096 [Poi2010]Pilots 单调队列
- bzoj2096【poi2010】Pilots
- 【POI2010】【BZOJ2096】Pilots
- BZOJ2096 [Poi2010]Pilots
- 【POI2010】BZOJ2096 pilots
- Python第一篇【安装及初体验】
- 2016年最后的一天,新年的到来!
- javascript的垃圾回收机制与内存管理
- zb的生日(01类搜索)
- 零基础学习java(四)
- 2096: [Poi2010]Pilots
- 今天是2016年的最后一天!!!
- 理解Spring AOP 原理(二)JDK,CGLIB动态代理以及ProxyFactory
- 明天就是2017年了
- 内核菜鸟的成长之路
- AngularJs学习二--路由、模块、依赖注入
- 这个怎么解析啊,求大神指点
- 【C#】List<T>对象的深复制
- iOS cell中添加按钮图片,图片不显示,点击有反应