bzoj2096: [Poi2010]Pilots
Description
Input
Output
Sample Input
5 1 3 5 8 6 6 9 10
Sample Output
(有两个子串的长度为4: 5, 8, 6, 6 和8, 6, 6, 9.最长子串的长度就是4)
HINT
Source
题解:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
char ch;
bool ok;
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
const int maxn=;
int k,n,v,hmin,tmin,hmax,tmax,ans,last;
struct Data{
int val,id;
}qmin[maxn],qmax[maxn];
int main(){
read(k),read(n);
hmin=hmax=,tmin=tmax=,last=;
for (int i=;i<=n;i++){
read(v);
while (hmin<=tmin&&qmin[tmin].val>v) tmin--;
qmin[++tmin]=(Data){v,i};
while (hmax<=tmax&&qmax[tmax].val<v) tmax--;
qmax[++tmax]=(Data){v,i};
while (hmin<=tmin&&hmax<=tmax&&qmax[hmax].val-qmin[hmin].val>k)
if (qmax[hmax].id<qmin[hmin].id) last=qmax[hmax++].id+;
else last=qmin[hmin++].id+;
ans=max(ans,i-last+);
}
printf("%d\n",ans);
return ;
}
bzoj2096: [Poi2010]Pilots的更多相关文章
- bzoj2096[Poi2010]Pilots 单调队列
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 983 Solved: 513[Submit][Statu ...
- 【单调队列】bzoj2096 [Poi2010]Pilots
用两个单调队列维护序列中的最大值和最小值即可. poi~ #include<cstdio> #include<algorithm> using namespace std; i ...
- 【BZOJ2096】[Poi2010]Pilots 双指针+单调队列
[BZOJ2096][Poi2010]Pilots Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...
- BZOJ 2096: [Poi2010]Pilots( set )
用个set维护就可以水过去...O(NlogN) 应该可以用单调队列O(N).... --------------------------------------------------------- ...
- BZOJ2096:[POI2010]Pilots
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...
- 【bzoj2096】[Poi2010]Pilots 双指针法+STL-set
题目描述 Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是不行的,于是他 ...
- BZOJ 2096: [Poi2010]Pilots
Description 求一个最长的序列,最大值最小值之差不超过 \(k\) . Sol 单调队列. 一个队列直接上就行.. Code /******************************* ...
- 【刷题】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: ...
随机推荐
- ios中的界面跳转方式
ios中,两种界面跳转方式 1.NavgationController本身可以作为普通ViewController的容器,它有装Controller的栈,所以可以push和pop它们,实现你所说的跳转 ...
- notification.setLatestEventInfo(context, title, message, pendingIntent); undefined
notification.setLatestEventInfo(context, title, message, pendingIntent); 在target为23时删除了该方法,我们应该使用 ...
- Oracle中wm_concat()的使用方法
以下两种方式使用wm_concat()的使用方法是等效的. 方法一:使用窗口函数,wm_concat支持窗口函数 select distinct classKey,className, classOr ...
- linux设置语言编码
前段时间在服务器上安装了centos6.2版本,当初安装时语言选择英文.这本来也没有什么问题,直到前一段时间.我的同事发现部署的web项目中出现乱码情况.但中文作为参数进行传递到下一个页面的时候就乱码 ...
- Linux编译安装MySQL5.6
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/4311061.html ...
- 纯javascript代码编写计算器程序
今天来分享一下用纯javascript代码编写的一个计算器程序,很多行业都能用到这个程序,例如做装修预算.贷款利率等等. 首先来看一下完成后的效果: 具体代码如下:(关注我的博客,及时获取最新WEB前 ...
- mysql修改root密码的方法
方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...
- linux,安装软件报错cannot create regular file '/usr/local/man/man1': No such file or directory
make install时报错,如下 install: cannot create regular file '/usr/local/man/man1': No such file or direct ...
- LinkedIn第三方登录
官方开发文档网址:https://developer.linkedin.com angularjs LinkedIn初始化 var apiKey='77n7z65hd7azmb';$(function ...
- 常用的dos命令之简略总结
Dos常用命令 一.基础命令 1 dir 无参数:查看当前所在目录的文件和文件夹. /s:查看当前目录已经其所有子目录的文件和文件夹. /a:查看包括隐含文件的所有文件. /ah:只显示出 ...