BZOJ2276:[POI2011]Temperature
浅谈队列: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的更多相关文章
- BZOJ2276: [Poi2011]Temperature
2276: [Poi2011]Temperature Time Limit: 20 Sec Memory Limit: 32 MBSubmit: 293 Solved: 117[Submit][S ...
- BZOJ2276 [Poi2011]Temperature 【单调队列】
题目链接 BZOJ2276 题解 一开始看错题,以为求的是可以不连续的,想出一个奇怪的线段树,发现空间根本开不下?? 题目要我们求连续的最长可能不下降区间 对于区间\([l,r]\)如果合法,当且仅当 ...
- bzoj2276: [Poi2011]Temperature(单调队列/堆)
这题有两种写法,而且是完全(几乎?)不一样的写法...并不是换了个方法来维护而已 单调队列O(N):用一个队列维护a[]的单调递减,对于每个i满足a[队头]<=b[i],然后就可以算出以每一位为 ...
- BZOJ 2276: [Poi2011]Temperature 单调队列
Code: #include<bits/stdc++.h> #define maxn 3000000 using namespace std; void setIO(string s) { ...
- BZOJ2527 & 洛谷3527:[Poi2011]Meteors——题解
+++++++++++++++++++++++++++++++++++++++++++ +本文作者:luyouqi233. + +欢迎访问我的博客:http://www.cnblogs.com/luy ...
- BZOJ2527:[POI2011]Meteors
浅谈离线分治算法:https://www.cnblogs.com/AKMer/p/10415556.html 题目传送门:https://lydsy.com/JudgeOnline/problem.p ...
- BZOJ2212:[POI2011]Tree Rotation
浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...
- [POI2011]Temperature
Description The Byteotian Institute of Meteorology (BIM) measures the air temperature daily. The mea ...
- Luogu3527:[POI2011]MET-Meteors
题面 Luogu Sol 整体二分 比较简单,当练手题 每次树状数组统计 # include <bits/stdc++.h> # define RG register # define I ...
随机推荐
- python中初始化实例属性
虽然我们可以自由地给一个实例绑定各种属性,但是,现实世界中,一种类型的实例应该拥有相同名字的属性.例如,Person类应该在创建的时候就拥有 name.gender 和 birth 属性,怎么办? 在 ...
- nf_conntrack之解决方案
1.现象 在/var/log/message中出现以下信息 Dec 8 11:22:29 product08 kernel: nf_conntrack: table full, dropping pa ...
- com.android.dex.DexIndexOverflowException: Cannot merge new index 66299 into a non-jumbo instruction
打包时控制台输出: Error:Execution failed for task ':app:transformClassesWithDexForAll32Release'. > com.an ...
- C++字符串操作库函数
#include <bits/stdc++.h> using namespace std; int main() { ]="; ]="abcdefg"; ]= ...
- linux下java unrecognized class file version错误的解决
root@Mr javaPC]# java HelloWorldException in thread “main” java.lang.ClassFormatError: HelloWorld (u ...
- numpy array或matrix的交换两行
A[j,:] = A[maxindex,:] # 注意这样是一个很低级的错误!这样只是赋值 我们很容易想起python中的两个值交换一句搞定不用引入中间变量 a, b = b, a 但在numpy的a ...
- aodh M版本新特性 - queue between alarm evaluator and alarm notifier
之前alarm evaluator service and alarm notifier services之间的通信采用RPC的方式,消耗较大,增加work queue的方式可以获得更好的性能, + ...
- python基础3 - 变量的基本使用和命名
4.变量的基本使用 4.1 变量定义 在 Python 中,每个变量 在使用前都必须赋值,变量 赋值以后 该变量 才会被创建 等号(=)用来给变量赋值 = 左边是变量名 = 右边是存储在变量中的值 变 ...
- 智课雅思词汇---十九、前缀se是什么意思
智课雅思词汇---十九.前缀se是什么意思 一.总结 一句话总结:前缀:se- 表示“分开, 离开, 区别开” 前缀:se- [词根含义]:分离 [同源单词]:secede, secession, s ...
- 《Think in Java》(九)接口
接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法: 抽象化类则是普通类与接口之间的一种中庸之道: 涨姿势了 接口也可以拥有值属性,但它们都是隐式的 static 和 final 的: 接 ...