BIT+离散化。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 200050 using namespace std; int n,t[maxn],sum[maxn],ans=0,x[maxn],y[maxn],ha[maxn],cnt=0; int lowbit(int x) {return (x&(-x));} void add(int x,int val) { for (int i=x;i<=cnt;i+=lowbit(i)) t[i]+=val; } int ask(int x) { int ret=0; for (int i=x;i>=1;i-=lowbit(i)) ret+=t[i]; return ret; } int find(int x) { return lower_bound(ha+1,ha+cnt+1,x)-ha; } int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d%d",&x[i],&y[i]); ha[++cnt]=x[i];ha[++cnt]=y[i]; } sort(ha+1,ha+cnt+1);cnt=unique(ha+1,ha+cnt+1)-ha-1; for (int i=1;i<=n;i++) { int a=find(x[i]),b=find(y[i]); add(a,1);add(b+1,-1); } for (int i=1;i<=cnt;i++) sum[i]=ask(i); for (int i=1;i<=cnt;i++) ans=max(ans,sum[i]); printf("%d ",ans); return 0; }