bzoj2096[Poi2010]Pilots

题意:

给一个序列和一个最大值,要求找一个最长连续子串,使里面任意两个数相差不超过这个最大值。序列大小≤3000000

题解:

用两个单调队列,分别维护当前区间的最大值和最小值,然后用双指针法。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define inc(i,j,k) for(int i=j;i<=k;i++)
 5 #define maxn 3000010
 6 using namespace std;
 7
 8 inline int read(){
 9     char ch=getchar(); int f=1,x=0;
10     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
11     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
12     return f*x;
13 }
14 struct nd{int v,pos;};
15 int n,a[maxn],k,l,r,ans,ql1,qr1,ql2,qr2; nd q1[maxn],q2[maxn];
16 int main(){
17     k=read(); n=read(); inc(i,1,n)a[i]=read();
18     l=1; r=1; ans=1; ql1=qr1=ql2=qr2=1; q1[1]=q2[1]=(nd){a[1],1};
19     while(r<n){
20         r++;
21         while(ql1<=qr1&&ql2<=qr2&&a[r]-q1[ql1].v>k){l++; if(l>q1[ql1].pos)ql1++; if(l>q2[ql2].pos)ql2++;}
22         while(ql1<=qr1&&ql2<=qr2&&q2[ql2].v-a[r]>k){l++; if(l>q1[ql1].pos)ql1++; if(l>q2[ql2].pos)ql2++;}
23         ans=max(ans,r-l+1);
24         while(ql1<=qr1&&a[r]<=q1[qr1].v)qr1--; q1[++qr1]=(nd){a[r],r};
25         while(ql2<=qr2&&a[r]>=q2[qr2].v)qr2--; q2[++qr2]=(nd){a[r],r};
26     }
27     printf("%d",ans); return 0;
28 }

20160829

转载于:https://www.cnblogs.com/YuanZiming/p/5838041.html

bzoj2096[Poi2010]Pilots*相关推荐

  1. [颓废史]蒟蒻的刷题记录

    QAQ蒟蒻一枚,其实我就是来提供水题库的. 以下记录从2016年开始. 1.1 1227: [SDOI2009]虔诚的墓主人 树状数组+离散化 3132: 上帝造题的七分钟 树状数组 二维区间加减+查 ...

  2. bzoj2096 pilots

    依旧是维护两个单调队列,只是队首检查的方式略有变动 1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 ...

  3. 用Lean Pilots推动改进

    在推动改进时,精益.敏捷和精益创业能彼此增强.Lean Pilots是一个数据驱动的改进框架,该框架适用于消除主要的跨职能组织障碍,已被用于推动内部持续改进. \\ Mariya Breyter是Du ...

  4. bzoj2091: [Poi2010]The Minima Game DP

    2091: [Poi2010]The Minima Game DP 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2091 思路 这类问题好迷 ...

  5. POJ 2965.The Pilots Brothers‘ refrigerator

    POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...

  6. The Pilots Brothers' refrigerator - poj 2965

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20325   Accepted: 7830   Special Judge ...

  7. P3511 [POI2010]MOS-Bridges(网络流/欧拉回路)

    P3511 [POI2010]MOS-Bridges 给出一个图,边正着走和反着走的边权不同,求解最大边权最小的欧拉回路,输出方案. 首先看到最大边权最小我们就可以想到二分答案,然后现在在剩余的图上我 ...

  8. 【POJ - 2965】The Pilots Brothers' refrigerator(暴力枚举,思维)

    题干: The game "The Pilots Brothers: following the stripy elephant" has a quest where a play ...

  9. poj 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...

最新文章

  1. 数据链路层和传输层的区别
  2. 1136 A Delayed Palindrome
  3. 《Redis入门指南(第2版)》一3.2 字符串类型
  4. 23LC1024四线访问数据
  5. Oracle数据处理
  6. 迷宫搜索问题最短路_迷宫的最短路问题(水+BFS宽搜)
  7. wireshark使用_使用 Wireshark 抓取数据包
  8. MFC实现mysql备份_MySQL如何自动备份 - MySQL - VC中文网-VC-MFC编程论坛 - Powered by Discuz!...
  9. Kubeadm installation
  10. Ubuntu,安装最新版的GCC
  11. 【LeetCode】【数组】题号:*4238. 除自身以外数组的乘积
  12. Centos 7 设置 SFTP
  13. 有限元工程应用方法-ANSYS单元刚度矩阵计算理论详解
  14. NetSetMan Pro(ip快速切换工具)官方中文版V5.1.0 | 电脑ip切换软件下载
  15. android信鸽推送demo_android app 集成 信鸽推送
  16. Ubuntu18.04 tc指令模拟网络丢包与延时
  17. 国外科研论文搜索网站汇总
  18. Android studio课程设计开发实现---日记APP
  19. python中__init_subclass__方法用法详解
  20. win11_中文包/中文输入法(微软拼音)设置/键盘/输入法移除win10启用单词输入法/基于英语语言包的美式键/半角切换设置开关

热门文章

  1. 深入编程之QQ盗号核心代码
  2. 大数据风控---Credit Kama商业模式分析
  3. GE董事长兼首席执行官杰夫.伊梅尔特上任第一年致诸位股东、客户与员工(中英文)
  4. MySQL客户端软件安装_003
  5. python pop3lib连接网易企业邮箱
  6. ——廖一梅《像我这样笨拙地生活》经典语录
  7. 全职宝妈卖出去5万多元的保暖袜子 只用这一招截流
  8. Vero VISI 2021.0.2109
  9. nyoj663弟弟的作业
  10. Python之正则表达式