依旧是维护两个单调队列,只是队首检查的方式略有变动

 /*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的更多相关文章

  1. 【BZOJ2096】[Poi2010]Pilots 双指针+单调队列

    [BZOJ2096][Poi2010]Pilots Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...

  2. bzoj2096[Poi2010]Pilots 单调队列

    2096: [Poi2010]Pilots Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 983  Solved: 513[Submit][Statu ...

  3. bzoj2096: [Poi2010]Pilots

    Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是 ...

  4. 【单调队列】bzoj2096 [Poi2010]Pilots

    用两个单调队列维护序列中的最大值和最小值即可. poi~ #include<cstdio> #include<algorithm> using namespace std; i ...

  5. BZOJ2096:[POI2010]Pilots

    浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...

  6. 【bzoj2096】[Poi2010]Pilots 双指针法+STL-set

    题目描述 Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是不行的,于是他 ...

  7. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  8. POJ2965The Pilots Brothers' refrigerator(枚举+DFS)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22057 ...

  9. The Pilots Brothers' refrigerator(dfs)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19718 ...

随机推荐

  1. java 21 - 13 IO流之 合并流

    SequenceInputStream :表示其他输入流的逻辑串联. 构造方法摘要 SequenceInputStream(Enumeration<? extends InputStream&g ...

  2. smarty初始化文件

    为了smarty初始化文件能方便其他目录下的脚步包含使用,应该将初始化文件里的引入smarty类及其他路径设置为全局路径,而不是相对路径 另外,如果模板里有文件的路径的引用,一定要是相对PHP脚本文件 ...

  3. isAnimated函数

    function isAnimated($obj){ var flag=false; if($obj.is(":animated")){ flag=true; } return f ...

  4. [py]os.walk爬目录&sys.argv灵活获取参数

    1, 遍历目录 os.walk('/tmp') os.next()   2,sys.argv ######################################## py@lanny:~/t ...

  5. [tools]camtasia studio8.6

    实际情况: 装了汉化补丁包后坏事,最后还是没装汉化补丁包.直接用英文版的.安装过程中输入序列号即可激活. ):输入注册码安装 用户名:大眼仔~旭(Anan) 注册码:GCABC-CPCCE-BPMMB ...

  6. 发发关于JavaScript的感慨,随手记几个js知识碎片

    最近一段时间写了很多JavaScript和jquery代码,越来越感觉js基础不牢固,写一句查半天,有时间肯定要系统的学一下. 不说了,先记一下最近学到的点东西,省的以后没时间系统学js还要再来查. ...

  7. log_bin_trust_function_creators变量解释

    在MySQL主从复制机器的master的数据库中创建function,报出如下错误: Error Code: 1418. This function has none of DETERMINISTIC ...

  8. ajax读取文本内容(此处的txt文件和html文件处于同级目录)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <style&g ...

  9. MVC 服务器文件下载

    文件上传到服务器后下载 window.open   与window.location.href  对txt  或是pdf文件执行的操作是打开,而非下载 mvc controller 自带有如下方法 p ...

  10. Objective-c归档的概念和用法