two-pointer型单调队列。。。。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1000050 using namespace std; int n,l[maxn],r[maxn],q[maxn],h=1,t=0,ans=0; int read() { char ch;int data=0,f=1; while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); } while (ch>='0' && ch<='9') { data=data*10+ch-'0'; ch=getchar(); } return data*f; } int main() { n=read(); for (int i=1;i<=n;i++) l[i]=read(),r[i]=read(); ans=1;q[++t]=1; for (int i=2;i<=n;i++) { while ((h<=t) && (l[i]>=l[q[t]])) t--; q[++t]=i; while ((h<=t) && (l[q[h]]>r[i])) h++; ans=max(ans,i-q[h-1]); } printf("%d\n",ans); return 0; }