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 ...
随机推荐
- 【Flask】Sqlalchemy group_by having
### group_by:根据某个字段进行分组.比如想要根据性别进行分组,来统计每个分组分别有多少人 ### having: having是对查找结果进一步过滤.比如只想要看未成年人的数量,那么可以首 ...
- js 工厂模式简要介绍
什么是工厂模式?就好比一个工厂,能造汽车.飞机...,通过对外接口,由顾客决定,来定制哪一款产品. 在js内表现为,一个工厂函数/对象,包含汽车.飞机等子类,提供对外接口,根据参数返回不同子类的实例 ...
- MVC6 (ASP.NET5) 认证 (Asp.net identity) cookie模式 自定义认证
1.Startup类的Configure方法中, app.UseIdentity(); 改为 app.UseCookieAuthentication(options => { options.A ...
- Get Started with ASP.NET Web API 2 (C#)
https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutoria ...
- spark学习4(zookeeper3.4集群搭建)
第一步:zookeeper安装 通过WinSCP软件将zookeeper-3.4.8.tar.gz软件传送到/usr/zookeeper/目录下 [root@spark1 zookeeper]# ch ...
- centos下安装Anaconda
第一步:将下载好的Anaconda2-4.1.1-Linux-x86_64.sh软件传到linux下 第二步:[hadoop@spark1 ~]$ cd Desktop #进入到该软件所在目录,我的放 ...
- Sqoop将MySQL表结构同步到hive(text、orc)
Sqoop将MySQL表结构同步到hive sqoop create-hive-table --connect jdbc:mysql://localhost:3306/sqooptest --user ...
- tyvj 1884 [NOIP2000T4]方格取数 || codevs 1043 dp
P1884 [NOIP2000T4]方格取数 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 [noip2000T4]方格取数 描述 设有N*N的方格图(N& ...
- dr03_
1.温州配调-->全网-->厂站-->瓯海-->竹溪变 1.1.“10kVI段”,“60号间隔”,手车开关 --> 合上 2. 2.1. 2.2. TdrSvgDll.A ...
- 语音01_TTS
1.http://blog.csdn.net/u010176014/article/details/47428595 2.家里 Win7x64 安装“微软TTS5.1语音引擎(中文).msi”之后,搜 ...