AC代码
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long ll;
struct node{
int x;
int y;
}a[1000013];
int n, cnt , ans;
bool cmp(node x,node y)
{
return x.y<y.y;
}
int main()
{
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;++i)
{
if(cnt<=a[i].x)
{
cnt = a[i].y;
ans++;
}
}
cout<<ans<<endl;
return 0;
}