bzoj2096 [Poi2010]Pilots
来源:互联网 发布:网络信息安全宣传语 编辑:程序博客网 时间:2024/06/04 08:43
题目
又是单调队列,好常见呀。
维护最大与最小即可。
#include<bits/stdc++.h>#define N 3000000using namespace std;int n,A[N+1],k,tmp,ans;int mx[N+1],mn[N+1];int lx,rx,ln,rn;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline int read(){ int x=0,b=1; char c=nc(); for(;!(c<='9'&&c>='0');c=nc())if(c=='-')b=-1; for(;c<='9'&&c>='0';c=nc())x=x*10+c-'0'; return x*b;}inline void write(int x){ if(x==0)putchar('0'); else { char buf[15]; int len=0; if(x<0)putchar('-'),x=-x; while(x)buf[++len]=x%10+'0',x/=10; for(int i=len;i>=1;i--)putchar(buf[i]); } putchar(' ');}int main(){ freopen("in.txt","r",stdin); k=read();n=read(); for(int i=1;i<=n;i++)A[i]=read(); lx=1,rx=0,ln=1,rn=0,tmp=0; for(int i=1;i<=n;i++) { while(lx<=rx&&A[i]>=A[mx[rx]])rx--;mx[++rx]=i; while(ln<=rn&&A[i]<=A[mn[rn]])rn--;mn[++rn]=i; while(A[mx[lx]]-A[mn[ln]]>k) { if(mx[lx]<mn[ln])tmp=mx[lx],lx++; else tmp=mn[ln],ln++; } ans=max(ans,i-tmp); } cout<<ans; return 0;}
阅读全文
0 0
- bzoj2096【poi2010】Pilots
- 【POI2010】【BZOJ2096】Pilots
- BZOJ2096 [Poi2010]Pilots
- 【POI2010】BZOJ2096 pilots
- bzoj2096 [Poi2010]Pilots
- 【bzoj2096】[Poi2010]Pilots
- BZOJ2096 [Poi2010]Pilots
- 【bzoj2096】[Poi2010]Pilots 单调队列
- [BZOJ2096][Poi2010]Pilots(单调队列)
- [bzoj2096][Poi2010]Pilots(二分+单调队列)
- bzoj2096 pilots
- BZOJ2096 Pilots
- BZOJ2096: [Poi2010]Pilot
- [BZOJ2096][POI]Pilots
- [BZOJ 2096]Poi2010 Pilots
- BZOJ 2096: [Poi2010]Pilots
- BZOJ 2096 [Poi2010]Pilots
- [BZOJ 2096][Poi2010]Pilots
- 5.0 Android 中多线程的用法大全
- A. Mahmoud and Ehab and the MEX
- STM32单片机学习详细局部介绍笔记
- 面向对象上(重点)
- hdu4513完美(马拉车模板题)
- bzoj2096 [Poi2010]Pilots
- SQL动态行转列
- Android 6.0 运行时权限处理完全解析
- [BZOJ1907]树的路径覆盖(贪心)
- 数据结构单链表创建(头插法,尾插法)java/c/c++
- 使用原生JavaScript实现jQuery的css选择器
- 输入一组数字,统计每个数字的个数后按序输出
- Codeforces Round #435 (Div. 2)C. Mahmoud and Ehab and the xor
- C语言如何改变一个常量的值和volatile关键字