P3522 [POI2011] TEM-Temperature
/* 某国进行了连续 nn ( 1≤n≤1,000,0001≤n≤1,000,000)天的温度测量,测量存在误差,测量结果是第 ii 天温度在 [li,ri][li,ri] 范围内。 求最长的连续的一段,满足该段内可能 温度不降》= 唯一判断标准 若这一天最大值<前一段的左端点的最大值 则不可能连在一起 用单调序列 维护左端点最大值 并记录这一段起始的标号 */ /* 6 6 10 1 5 4 8 2 5 6 8 3 5 4 */ #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<string.h> #include<queue> #include<deque> #include<vector> #include<bits/stdc++.h> typedef long long ll; #define ddd printf("-----------------------\n"); using namespace std; const int maxn=1e1 +10; const int mod=998244353; const int inf=0x3f3f3f3f; int n,ans=1; struct node{ int l,r,id; }; deque<node> q; int main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++) { int tl,tr;cin>>tl>>tr; while(q.empty()==0&&tr<q.front().l){ q.pop_front(); } if(q.empty()==0){ ans=max(ans,i-q.front().id+1); } int tmp=i;//last pop while(q.empty()==0&&tl>q.back().l){ tmp=q.back().id; q.pop_back(); } q.push_back((node){tl,tr,tmp}); } cout<<ans<<'\n'; return 0; }