BZOJ 2096: [Poi2010]Pilots
Description
求一个最长的序列,最大值最小值之差不超过 \(k\) .
Sol
单调队列.
一个队列直接上就行..
Code
/**************************************************************
Problem: 2096
User: BeiYu
Language: C++
Result: Accepted
Time:4024 ms
Memory:71604 kb
****************************************************************/ #include <bits/stdc++.h>
using namespace std; #define debug(a) cout<<#a<<"="<<a<<" " typedef long long LL;
const int N = 3e6+50; LL n,k,ans;
LL a[N];
LL q[2][N],h[2],t[2],l; inline LL in(LL x=0,char ch=getchar()) { while(ch>'9' || ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x; }
int main() {
k=in(),n=in();
for(int i=1;i<=n;i++) a[i]=in(); ans=1;
q[0][h[0]=t[0]=1]=1,q[1][h[1]=t[1]=1]=1,l=1; for(int i=2;i<=n;i++) {
while(h[0]<=t[0] && a[i]<a[q[0][t[0]]]) t[0]--;
q[0][++t[0]]=i; // cout<<i<<":"<<endl;
// for(int j=h[0];j<=t[0];j++) cout<<q[0][j]<<endl; while(h[1]<=t[1] && a[i]>a[q[1][t[1]]]) t[1]--;
q[1][++t[1]]=i; // for(int j=h[1];j<=t[1];j++) cout<<q[1][j]<<endl; for(;a[q[1][h[1]]]-a[q[0][h[0]]]>k;l++) {
if(q[0][h[0]]==l) h[0]++;
if(q[1][h[1]]==l) h[1]++;
}
ans=max(ans,i-l+1);
// debug(l),debug(ans)<<endl;
// cout<<"--------------------"<<endl;
}cout<<ans<<endl;
return 0;
}
BZOJ 2096: [Poi2010]Pilots的更多相关文章
- BZOJ 2096: [Poi2010]Pilots( set )
用个set维护就可以水过去...O(NlogN) 应该可以用单调队列O(N).... --------------------------------------------------------- ...
- 【刷题】BZOJ 2096 [Poi2010]Pilots
Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是 ...
- BZOJ——2096: [Poi2010]Pilots
http://www.lydsy.com/JudgeOnline/problem.php?id=2096 Time Limit: 30 Sec Memory Limit: 162 MBSubmit: ...
- BZOJ 2096: [Poi2010]Pilots 单调队列
Code: #include<bits/stdc++.h> #define maxn 4000000 using namespace std; void setIO(string s) { ...
- BZOJ 2096([Poi2010]Pilots-单调队列-差值)
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MB Submit: 190 Solved: 97 [ Submit][ ...
- bzoj2096[Poi2010]Pilots 单调队列
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 983 Solved: 513[Submit][Statu ...
- 【BZOJ2096】[Poi2010]Pilots 双指针+单调队列
[BZOJ2096][Poi2010]Pilots Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...
- BZOJ 2096 Pilots - 单调队列STL(deque)
传送门 分析: 单调队列:维护两个递增.递减的队列,每次都加入新元素并更新,如果最大值(递减队首)-最小值(递增队首) > k,那么将最左段更新为前面两者中较前的那一个,并弹掉.用deque可以 ...
- BZOJ 2080: [Poi2010]Railway 双栈排序
2080: [Poi2010]Railway Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 140 Solved: 35[Submit][Statu ...
随机推荐
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [网站性能3]SqlServer中Profiler的使用
原文链接:http://www.cnblogs.com/caishuhua226/p/3838060.html http://www.cnblogs.com/lyhabc/articles/294 ...
- CDQ分治
要求可以计算前面的操作对后面询问的贡献 BZOJ1176 #include <cstdio> #include <algorithm> using namespace std; ...
- RedisUtil 工具类
package com.test; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import red ...
- Beta版本冲刺第三天
Aruba 408 409 410 428 429 431 完成任务: 分类界面,实现手动新增/删除分类 分类界面,设置确定和取消按钮的intent 实现图片在编辑界面导入并合理摆放 立会照片: 燃尽 ...
- js 闭包
this.color = "blue"; (function(_this) { setInterval(function() { if (_this.color !== " ...
- SOA 实现:服务设计原则
http://www.ibm.com/developerworks/cn/webservices/ws-soa-design/ 引言 面向服务的体系结构(Service-Oriented Archit ...
- 各个浏览器显示版本(IE,火狐)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 练习用基础SQL语句
http://www.cnblogs.com/zxlovenet/p/3728842.html 本文语句大部分SQL语句来自<数据库系统概论>(第四版)王珊&萨师煊 ,是我们上课用 ...
- bootstrap开发一个简单网页。
CSS代码: body{ padding-top: 50px; padding-bottom: 50px; overflow: auto!important; ...