浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html

题目传送门:https://lydsy.com/JudgeOnline/problem.php?id=2276

假设一段区间满足不降的要求,那么充要条件是\(l_{max}<=r_{min}\)

所以我们用单调队列维护\(l\)的最大值然后更新答案即可。

时间复杂度:\(O(n)\)

时间复杂度:\(O(n)\)

代码如下:

#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=1e6+5; int n,head,tail,ans,pos;
int l[maxn],r[maxn],list[maxn]; int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
} int main() {
n=read();
for(int i=1;i<=n;i++)
l[i]=read(),r[i]=read();
for(int i=1;i<=n;i++) {
while(head!=tail&&l[list[tail-1]]<l[i])tail--;
while(head!=tail&&l[list[head]]>r[i])pos=list[head++];
list[tail++]=i;ans=max(ans,i-pos);
}
printf("%d\n",ans);
return 0;
}

BZOJ2276:[POI2011]Temperature的更多相关文章

  1. BZOJ2276: [Poi2011]Temperature

    2276: [Poi2011]Temperature Time Limit: 20 Sec  Memory Limit: 32 MBSubmit: 293  Solved: 117[Submit][S ...

  2. BZOJ2276 [Poi2011]Temperature 【单调队列】

    题目链接 BZOJ2276 题解 一开始看错题,以为求的是可以不连续的,想出一个奇怪的线段树,发现空间根本开不下?? 题目要我们求连续的最长可能不下降区间 对于区间\([l,r]\)如果合法,当且仅当 ...

  3. bzoj2276: [Poi2011]Temperature(单调队列/堆)

    这题有两种写法,而且是完全(几乎?)不一样的写法...并不是换了个方法来维护而已 单调队列O(N):用一个队列维护a[]的单调递减,对于每个i满足a[队头]<=b[i],然后就可以算出以每一位为 ...

  4. BZOJ 2276: [Poi2011]Temperature 单调队列

    Code: #include<bits/stdc++.h> #define maxn 3000000 using namespace std; void setIO(string s) { ...

  5. BZOJ2527 & 洛谷3527:[Poi2011]Meteors——题解

    +++++++++++++++++++++++++++++++++++++++++++ +本文作者:luyouqi233. + +欢迎访问我的博客:http://www.cnblogs.com/luy ...

  6. BZOJ2527:[POI2011]Meteors

    浅谈离线分治算法:https://www.cnblogs.com/AKMer/p/10415556.html 题目传送门:https://lydsy.com/JudgeOnline/problem.p ...

  7. BZOJ2212:[POI2011]Tree Rotation

    浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...

  8. [POI2011]Temperature

    Description The Byteotian Institute of Meteorology (BIM) measures the air temperature daily. The mea ...

  9. Luogu3527:[POI2011]MET-Meteors

    题面 Luogu Sol 整体二分 比较简单,当练手题 每次树状数组统计 # include <bits/stdc++.h> # define RG register # define I ...

随机推荐

  1. WebSocket 的后记

    一个美好的概念可以让策划无比幼稚和疯狂, 比如 H5 改变世界呀,小程序替代 APP 呀,现在即时通信也被公司里的他们认为 so easy 了. 这很尴尬好吧,WebSocket(以下简称 ws) 的 ...

  2. 初识python---简介,简单的for,while&if

    一编程语言:编程语言是程序员与计算机沟通的介质: 编程语言的分类:  1机器语言:是用二进制代码表示的计算机能直接识别和执行的一种机器指令的集合.           优点:灵活,直接执行和速度快   ...

  3. 正则表达式----grep

    正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. grep [参数]  匹配条件  路径  参数 : -n  :显示行号 ...

  4. display:inline-block 间隙

    IE6/7是不支持display:inline-block属性,只是让其表现的跟inline-block一样,尤其对于inline水平的元素,其表现度可以用perfect一词来形容了. 对于IE8+以 ...

  5. css transform常用变化解析

    本文旨在对常用变化做最直观的简析 translate 移动 translateX() X轴正方向移动(单位可为px,也可为%,为%时以自身为参照物) translateY() Y轴反方向移动 tran ...

  6. css异步加载

    <link rel="preload" href="mystyles.css" as="style" onload="thi ...

  7. C#多线程学习之Thread

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. Go sync模块

    // A WaitGroup waits for a collection of goroutines to finish.// The main goroutine calls Add to set ...

  9. python装饰器实现HTTP请求耗时和入参返回日志记录

    装饰器方法: 1 def decoArgs(server_name): 2 def deco(func): 3 def wrapper(view, request, *args, **kwargs): ...

  10. 使用Properties读写属性文件

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /*Prop ...