浅谈队列: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. CSS3 3D旋转下拉菜单

    在线演示 本地下载

  2. awk的getline命令

    原文出处:生活费的博客,http://www.cnblogs.com/276815076/archive/2011/12/05/2276625.html#undefined  两种情况:getline ...

  3. React Native中组件的props和state

    一.组件的属性(props)和状态(state) 1.属性(props) 它是组件的不可变属性(组件自己不可以自己修改props). 组件自身定义了一组props作为对外提供的接口,展示一个组件时只需 ...

  4. python 中文字符的处理

    刚开始学习python的时候,都是对这英文的翻译书学习的.没有解除到中文编码的相关问题,直到自己用python去做相关的项目的时候才发先中文编码问题真的非常头疼啊.这里分享一下本人所了解的一些经验. ...

  5. 如何判断Linux服务器是否被入侵?

    被入侵服务器的症状 当服务器被没有经验攻击者或者自动攻击程序入侵了的话,他们往往会消耗 100% 的资源.他们可能消耗 CPU 资源来进行数字货币的采矿或者发送垃圾邮件,也可能消耗带宽来发动 DoS ...

  6. centos安装zabbix监控服务器端

    首先安装zabbx 依赖yum install net-snmp-devel libxml2-devel libcurl-devel -y 下载zabbix 源码包wget https://ncu.d ...

  7. ElasticSearch入门常用命令

    基于开源项目MyAlice智能客服学习ElasticSearch https://github.com/hpgary/MyAlice/wiki/%E7%AC%AC01%E7%AB%A0%E5%AE%8 ...

  8. Ubuntu 安装mysql

    ubuntu上安装mysql非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server   2. apt-get isntall mysql-clie ...

  9. QT 使用QUdpSocket QUdpServer UDP 建立客户端与服务器端

    1. 模拟天气监控,每隔两秒从Server发送天气信息到Client. 2. 示例代码 --------------------------- Server 端 ------------------- ...

  10. 在虚拟机里安装ubuntu

    1.下载ubuntu镜像文件 https://mirrors.aliyun.com/ubuntu-releases/17.04/ubuntu-17.04-desktop-amd64.iso 2.创建虚 ...