https://www.luogu.com.cn/problem/CF845C
差分+离散化
#include<bits/stdc++.h>
using namespace std;
int a[700100],s[700100],se[700100],e[700100];//2*n的范围
int main()
{
int n,sum=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i]>>e[i];
se[2*i-1]=s[i],se[2*i]=e[i];
}
sort(se+1,se+1+2*n);
int ms=unique(se+1,se+1+2*n)-1-se;
for(int i=1;i<=n;i++)
{
s[i]=lower_bound(se+1,se+1+ms,s[i])-se;
e[i]=lower_bound(se+1,se+1+ms,e[i])-se;
}
for(int i=1;i<=n;i++)
{
a[s[i]]++;
a[e[i]+1]--;
}
for(int i=0;i<=2*n;i++) //可能从零开始
{
sum+=a[i];
if(sum>2)
{
cout<<"NO";
return 0;
}
}
cout<<"YES";
return 0;
}```