【题解】
线段覆盖问题。线段树或者并查集都可以。不离散化居然能过?
#include<cstdio>
#include<algorithm>
#define N 10000010
#define rg register
using namespace std;
int n,m,ans,l[N],r[N],fa[N];
inline int read(){
int k=0,f=1; char c=getchar();
while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
return k*f;
}
inline int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
n=read(); m=read();
for(rg int i=1;i<=m;i++){
l[i]=read(); r[i]=read();
}
for(rg int i=1;i<=n+1;i++) fa[i]=i;
for(rg int i=m;i;i--){
int p=find(l[i]); bool fg=0;
while(p<=r[i]) fa[p]=find(p+1),p=fa[p],fg=1;
ans+=fg;
}
return printf("%d\n",ans),0;
}