Description

The Byteotian Institute of Meteorology (BIM) measures the air temperature daily. The measurement is done automatically, and its result immediately printed. Unfortunately, the ink in the printer has long dried out... The employees of BIM however realised the fact only recently, when the Byteotian Organisation for Meteorology (BOM) requested access to that data.

An eager intern by the name of Byteasar saved the day, as he systematically noted down the temperatures reported by two domestic alcohol thermometers placed on the north and south outside wall of the BIM building. It was established decades ago by various BIM employees that the temperature reported by the thermometer on the south wall of the building is never lower than the actual temperature, while that reported by the thermometer on the north wall of the building is never higher than the actual temperature. Thus even though the exact temperatures for each day remain somewhat of a mystery, the range they were in is known at least.

Fortunately for everyone involved (except Byteasar and you, perhaps), BOM does not require exact temperatures. They only want to know the longest period in which the temperature was not dropping (i.e. on each successive day it was no smaller than on the day before). In fact, the veteran head of BIM knows very well that BOM would like this period as long as possible. To whitewash the negligence he insists that Byteasar determines, based on his valuable notes, the longest period in which the temperature could have been not dropping. Now this is a task that Byteasar did not quite expect on his BIM internship, and he honestly has no idea how to tackle it. He asks you for help in writing a program that determines the longest such period.

某国进行了连续n天的温度测量,测量存在误差,测量结果是第i天温度在[l_i,r_i]范围内。

求最长的连续的一段,满足该段内可能温度不降。

Input

In the first line of the standard input there is one integer n(1<=N<=1000000) that denotes the number of days for which Byteasar took notes on the temperature. The measurements from day are given in the line no.i+1 Each of those lines holds two integers, x and y (-109<=x<=y<=109). These denote, respectively, the minimum and maximum possible temperature on that particular day, as reported by the two thermometers.

In some of the tests, worth 50 points in total, the temperatures never drop below -50 degrees (Celsius, in case you wonder!) and never exceeds 50 degrees (-50<=x<=y<=50)

第一行n

下面n行,每行l_i,r_i

1<=n<=1000000

Output

In the first and only line of the standard output your program should print a single integer, namely the maximum number of days for which the temperature in Byteotia could have been not dropping.

一行,表示该段的长度

Sample Input

6

6 10

1 5

4 8

2 5

6 8

3 5

Sample Output

4


首先,一段子串[x,y]满足题意,当且仅当这段区间Li的最大值小于等于Ry并且[x,y-1]合法

所以我们可以用给一个单调队列进行维护,对l维护一个单调递减的队列,保证队头的l小于等于队尾的r

然后统计最大差值即可

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline 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<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1e6;
struct S1{
int l,r;
void insert(int _l,int _r){l=_l,r=_r;}
}A[N+10];
int h[N+10];
int main(){
int n=read();
for (int i=1;i<=n;i++){
int l=read(),r=read();
A[i].insert(l,r);
}
A[0].insert(-inf,0);
A[n+1].insert(0,inf);
int head=1,tail=1,Ans=0;
h[1]=1;
for (int i=1,j=1;i<=n;i++){
if (j==i) j++;
if (h[head]==i-1) head++;
while (j<=n&&A[h[head]].l<=A[j].r){
while (head<=tail&&A[h[tail]].l<=A[j].l) h[tail--]=0;
h[++tail]=j++;
}
Ans=max(Ans,j-i);
}
printf("%d\n",Ans);
return 0;
}

[POI2011]Temperature的更多相关文章

  1. BZOJ2276: [Poi2011]Temperature

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

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

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

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

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

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

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

  5. bzoj 2276: [Poi2011]Temperature——单调队列

    Description 某国进行了连续n天的温度测量,测量存在误差,测量结果是第i天温度在[l_i,r_i]范围内. 求最长的连续的一段,满足该段内可能温度不降 第一行n 下面n行,每行l_i,r_i ...

  6. BZOJ2276:[POI2011]Temperature

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

  7. POI2011题解

    POI2011题解 2214先咕一会... [BZOJ2212][POI2011]Tree Rotations 线段树合并模板题. #include<cstdio> #include< ...

  8. [原博客] POI系列(4)

    正规.严谨.精妙. -POI BZOJ 1531 : [POI2005]Bank notes 裸的背包,可以二进制拆分一下.一个物品比如说有n个,可以拆成 1,2,4,8,16...个. OJ上没有样 ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. Web容器自己主动对HTTP请求中參数进行URLDecode处理

    这篇文章转载自 : Web容器自己主动对HTTP请求中參数进行URLDecode处理 如题.在Java中或许非常多人都没有注意到当我们发送一个http请求时,假设附带的參数被URLEncode之后,到 ...

  2. Android消息机制1-Handler(Java层)(转)

    转自:http://gityuan.com/2015/12/26/handler-message-framework/ 相关源码 framework/base/core/java/andorid/os ...

  3. 【转】SQL中的取整函数FLOOR、ROUND、CEIL、TRUNC、SIGN

    --------------------------------------------------------------------------1 trunc(value,precision)按精 ...

  4. Android第一个个人APP(帐号助手)

    第一个app上线了,关于帐号保存的一个app.本地保存,无须联网. 下载地址为:http://android.myapp.com/myapp/detail.htm?apkName=com.weeky. ...

  5. 全栈JavaScript之路(十六)HTML5 HTMLDocument 类型的变化

    HTML5 扩展了 HTMLDocument, 添加了新的功能. 1.document.readState = 'loading' || 'complete'  //支持readyState 属性的浏 ...

  6. 学习Opencv 2.4.9 (一)---Opencv + vs2012环境配置

    作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 首先获得最新的Opencv 2.4.9源代码:opencv源代码下载 一.Opencv环境变量配置 ...

  7. vsCode 常用快捷键(mac 版)

    光标多行显示: commond+Alt+topArrow/downArrow 查找:commond+F 查找并按顺序切换下一个:commond+G 跳转到某一行: ctrl+G 输入行号跳转 跳转到某 ...

  8. C++ 函数部分(2)

    C++函数的递归调用 函数可以直接或间接地调用自身,称为递归调用.所谓直接调用自身,就是指在一个函数的函数体中出现了对自身的调用表达式,例如: void fun1(void) { //do somet ...

  9. 设置一个DIV块固定在屏幕中央(两种方法)

    设置一个DIV块固定在屏幕中央(两种方法) 方法一: 对一个div进行以下设置即可实现居中. <style> #a{ position: fixed; top: 0px; left: 0p ...

  10. FineReport实现java报表统计图表的效果图

    Java报表-ERP图表联动 Java报表-多维坐标轴图 Java报表-静态图表 Java报表-时间坐标轴 Java报表-图表报表动态交互 Java报表-图表热点链接 Java报表-图表缩放 Java ...