[洛谷P3512 [POI2010]PIL-Pilots]
题目链接:###
题目分析:###
感觉不是很难啊……不像是蓝题(AC量也不像)恶意评分?
少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还想水篇题解的
单调队列分别维护序列最大值和最小值,如果极差\(>k\)的话就扔掉最大值和最小值里面靠前的那一个,因为你不能不改动这个连续子序列的左端点而从中间丢掉一个值。同时记录下这个序列的左端点\(last_l\)是扔掉的那个值的编号+1(只要丢掉这个值,剩下的序列就合法了),丢完之后更新\(ans=max(ans,i-last_l+1)\)即可。时间复杂度为\(O(n)\)。
其实是一道不错的单调队列题。
题做少了看什么题都感觉眉清目秀的
代码:###
#include<bits/stdc++.h>
#define N (3000000+5)
using namespace std;
inline int read(){
int cnt=0,f=1;char c;
c=getchar();
while(!isdigit(c)){
if(c=='-')f=-f;
c=getchar();
}
while(isdigit(c)){
cnt=cnt*10+c-'0';
c=getchar();
}
return cnt*f;
}
int n,k,l1=1,r1=0,x,ans,l2=1,r2=0;
int last_l=1;
struct node{
int dat;int pos;
} q1[N],q2[N];
int main(){
k=read();n=read();
if(n==1) {
printf("1");
return 0;
}
for(register int i=1;i<=n;i++){
x=read();
while(l1<=r1&&q1[r1].dat>x)r1--;
q1[++r1].dat=x;q1[r1].pos=i;
while(l2<=r2&&q2[r2].dat<x)r2--;
q2[++r2].dat=x;q2[r2].pos=i;
while(q2[l2].dat-q1[l1].dat>k){
if(q1[l1].pos<q2[l2].pos&&l1<=r1){
last_l=q1[l1].pos+1;
l1++;
}
if(q1[l1].pos>=q2[l2].pos&&l2<=r2){
last_l=q2[l2].pos+1;
l2++;
}
}
if(i-last_l+1>ans)ans=i-last_l+1;
}
printf("%d",ans);
return 0;
}
[洛谷P3512 [POI2010]PIL-Pilots]的更多相关文章
- 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...
- [洛谷P3501] [POI2010]ANT-Antisymmetry
洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...
- 洛谷 P3496 [POI2010]GIL-Guilds
P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...
- 洛谷 P3507 [POI2010]GRA-The Minima Game
P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...
- 洛谷 P3505 [POI2010]TEL-Teleportation
P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...
- 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解
这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...
- 洛谷P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
- [洛谷P3509][POI2010]ZAB-Frog
题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...
- 洛谷 P3375 【模板】KMP字符串匹配
我这段时间因为字符串太差而被关了起来了(昨晚打cf不会处理字符串现场找大佬模板瞎搞,差点就凉了),所以决定好好补一下字符串的知识QAQ,暂时先学习kmp算法吧~ 题目链接:https://www.lu ...
随机推荐
- 减肥 day1
今天是我减肥第一天,现在体重是147斤, 早晨吃了一碗面,喝了一碗奶,中午吃了一个apple. 6点钟去打篮球,晚上去食堂稍微吃一点东西.
- c3p0+spring
1. 首先是jdbc.properties属性文件的编写,便于数据库移植: datasource.driverClassName=oracle.jdbc.driver.OracleDriverdata ...
- poj 1742 Coins(二进制拆分+bitset优化多重背包)
\(Coins\) \(solution:\) 这道题很短,开门见山,很明显的告诉了读者这是一道多重背包.但是这道题的数据范围很不友好,它不允许我们直接将这一题当做01背包去做.于是我们得想一想优化. ...
- jQuery制作信息提示弹出层插件【推荐】
给大家分享一款非常实用的弹窗提示窗口插件,包含多种模式.带有回执函数值的功能.1. [代码][JavaScript]代码 <script type="text/javascript& ...
- PHP加密方式。 base!base!base!
PHP中的加密方式有如下几种 1. MD5加密 string md5 ( string $str [, bool $raw_output = false ] ) 参数 str -- 原始字符串. ...
- Pycharm中如何安装python库
1首先打开pycharm工具,选择File中的Setting选项,如下图所示 2在打开的setting界面中我们点击python的解释器,你会看到很多导入的第三方库,如下图所示,点击最右边的加号 3在 ...
- ubuntu openjdk 7 升级 8
/******************************************************************************* * ubuntu openjdk 7 ...
- JAVA GUI THREAD---***
针对用户界面的多线程 GUI下面的多线程方式 1.与GUI类分离方式 分离方式,在创建线程类实例时需要代入GUI句柄,通过GUI句柄操作GUI,也就是说线程类和GUI类都要有对方的实例,以便相互操作. ...
- 杂项:ASP.NET Core
ylbtech-杂项:ASP.NET Core 1.返回顶部 1. ASP.NET Core 是一个跨平台的高性能开源框架,用于生成基于云且连接 Internet 的新式应用程序.使用 ASP.NET ...
- centos7 编译安装新版LNMP环境
centos7 编译安装新版LNMP环境 环境版本如下: 1.系统环境:Centos 7 x86_64 2.NGINX:nginx-1.11.3.tar.gz 3.数据库:mariadb-10.0.2 ...