题目链接:###

传送门走这里

题目分析:###

感觉不是很难啊……不像是蓝题(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]的更多相关文章

  1. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  2. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  3. 洛谷 P3496 [POI2010]GIL-Guilds

    P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...

  4. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  5. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  6. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  7. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  8. [洛谷P3509][POI2010]ZAB-Frog

    题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...

  9. 洛谷 P3375 【模板】KMP字符串匹配

    我这段时间因为字符串太差而被关了起来了(昨晚打cf不会处理字符串现场找大佬模板瞎搞,差点就凉了),所以决定好好补一下字符串的知识QAQ,暂时先学习kmp算法吧~ 题目链接:https://www.lu ...

随机推荐

  1. Windows7和Ubuntu12.04无法选择系统

    Windos7 旗舰版 Ubuntu12.04LTS 64位版本号 硬件挂载两个硬盘 SSD+机械 Windows7和Ubuntu12.04都装在SSD上.眼下先装好了Windows7,打算装Ubun ...

  2. LeetCode——Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  3. atitit.eclipse有多少api&#160;&#160;扩展点,以及扩展点的设计

    atitit.eclipse有多少api  扩展点,以及扩展点的设计 不赞成使用的.作废的以及内部的扩展点 [扩展]页显示了几个你不应该在你的插件中使用的扩展点.在附表C.1的[描写叙述]栏中.我们使 ...

  4. 写入文本文件时“\n”不是回车换行而是个方块“■”的解决方法

    用“\n”写入文本文件时,打开文本文件显示的为什么不是回车换行而是个黑方块“■”,但用file()读取时还是认为是一行一行的? 首先在WINDOWS里回车换行是"\r\n"; 而L ...

  5. org.gradle.api.publication.maven.internal.DefaultMavenFactory错误

    Error:Unable to load class 'org.gradle.api.publication.maven.internal.DefaultMavenFactory'. Possible ...

  6. ubuntu 本地和服务器scp文件传输

    安装 SSH(Secure Shell) 服务以提供远程管理服务 sudo apt-get install ssh SSH 远程登入 Ubuntu 机 ssh username@192.168.0.1 ...

  7. SDUT OJ 1221 亲和数 (找出某个数n所有的因子数,只需要暴力:2->sqrt(n) 即可 )

    亲和数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 如果a的因子和等于b,b的因子和等于a,且a≠b,则称a,b为亲和数对. ...

  8. 逻辑运算符,if、swtch语句(java基础知识三)

    1.逻辑运算符的基本用法 * A:逻辑运算符有哪些 &(逻辑与) |(逻辑或) !(逻辑非) ^(逻辑异或) &&(短路与) ||(短路或) * 注意事项: * a:逻辑运算符 ...

  9. oracle:os认证用户登录测试

        90%的情况下,我们使用的都是数据库认证用户登录oracle,但还存在使用OS认证用户登录oracle的情况: 下面就实验一下OS用户要登录oracle相关操作: 测试环境:oracle10. ...

  10. NOIP2003题解

    传送门 考查题型 搜索 字符串 模拟 dp T1 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷 ...