bzoj2096 pilots
依旧是维护两个单调队列,只是队首检查的方式略有变动
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
struct que{
int v;//val
int p;//pos
};
que mx[mxn],mi[mxn];
int h1,h2,t1,t2;
int k,n;
int a[mxn];
int ans=;
int main(){
scanf("%d%d",&k,&n);
int i,j;
for(i=;i<=n;i++)scanf("%d",&a[i]);
h1=;h2=;t1=;t2=;
int le=;
for(i=;i<=n;i++){
//max
while(h1<=t1 && a[i]>=mx[t1].v)t1--;
mx[++t1].v=a[i];
mx[t1].p=i;
//min
while(h2<=t2 && a[i]<=mi[t2].v)t2--;
mi[++t2].v=a[i];
mi[t2].p=i; printf("test1 %d\n",mx[h1].v-mi[h2].v);
while(mx[h1].v-mi[h2].v>k){//若两队首元素差大于k,更新队头
le=min(mx[h1].p,mi[h2].p)+;
while(le>mx[h1].p)h1++;//队首维护
while(le>mi[h2].p)h2++; }
printf("test2 %d\n",mx[h1].v-mi[h2].v);
ans=max(ans,i-le+);
}
printf("%d\n",ans-1);
return ;
}
bzoj2096 pilots的更多相关文章
- 【BZOJ2096】[Poi2010]Pilots 双指针+单调队列
[BZOJ2096][Poi2010]Pilots Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...
- bzoj2096[Poi2010]Pilots 单调队列
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 983 Solved: 513[Submit][Statu ...
- bzoj2096: [Poi2010]Pilots
Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是 ...
- 【单调队列】bzoj2096 [Poi2010]Pilots
用两个单调队列维护序列中的最大值和最小值即可. poi~ #include<cstdio> #include<algorithm> using namespace std; i ...
- BZOJ2096:[POI2010]Pilots
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...
- 【bzoj2096】[Poi2010]Pilots 双指针法+STL-set
题目描述 Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是不行的,于是他 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ2965The Pilots Brothers' refrigerator(枚举+DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22057 ...
- The Pilots Brothers' refrigerator(dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19718 ...
随机推荐
- JMeter学习参数化User Defined Variables与User Parameters
偶然发现JMeter中有两个元件(User Defined Variables与User Parameters)很相近,刚开始时我也没注意,两者有什么不同.使用时却发现两者使用场景有些不同,现在小结一 ...
- 27Spring_的事务管理_银行转账业务加上事务控制_基于tx.aop进行声明式事务管理
上一篇文章中,银行转账业务没有使用事务,会出现问题,所以这篇文章对上篇文章出现的问题进行修改. 事务 依赖 AOP , AOP需要定义切面, 切面由Advice(通知) 和 PointCut(切点) ...
- jade 渲染js片段
script. str = !{JSON.stringify(val)}; res.render('wxpay', {val:result});
- es2自动发现插件
https://www.elastic.co/guide/en/elasticsearch/plugins/current/discovery-multicast-usage.html http:// ...
- NET中MSMQ的使用----附例子
目录 一:MSMQ的一些理论上的知识 二:队列类型(Queue Type) 三:安装消息队列 四:在C#中Messagequeue class 五:MSMQ-发送消息到远程专用队列 六:例子 一. ...
- python爬虫中文网页cmd打印出错问题解决
问题描述 用python写爬虫,很多时候我们会先在cmd下先进行尝试. 运行爬虫之后,肯定的,我们想看看爬取的结果. 于是,我们print... 运气好的话,一切顺利.但这样的次数不多,更多地,我们会 ...
- 解决SaveChanges会Hold住之前的错误的问题
问题描述: 在一次新增操作中,由于有一个必填字段忘记写了,然后直接点击提交,运行到savechanges的地方,程序报错,提示***字段为必填字段. 然后关掉页面,重新填写一次,这次什么都填写上了,一 ...
- 实践:VIM深入研究(20135301 && 20135337)
目录 一.基本知识 1.vim模式介绍 2.三种常用模式的切换 二.Vim文档编辑 1.vim重复命令 2.游标的快速跳转 3.复制粘贴和剪切 4.删除文本 5.字符的替换及撤销(Undo操作) 6. ...
- 亚博 Arduino智能小车实验报告
亚博 Arduino智能小车实践报告 一. 程序安装准备 首先安装了Arduino板载USB转串口CH340驱动安装包, 若上述程序安装成功,则可以在我的电脑中找到相应的端口 本机端口号为CO ...
- Opencv step by step - 阈值化
Opencv里面的阈值化做起来比较简单,只需要一个函数即可: /* Applies fixed-level threshold to grayscale image. This is a basic ...