题目描述

解题代码
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
const int N=1e5+10;
vector<PII> a,b;
int n;
void merge()
{
int st=-2e9,ed=-2e9;
for(auto t:a)
{
if(ed<t.first)
{
if(st!=-2e9) b.push_back({t.first,t.second});
st=t.first,ed=t.second;
}
else
{
ed=max(ed,t.second);
}
}
if(st!=-2e9) b.push_back({st,ed});
}
int main()
{
cin >> n;
for(int i=0;i<n;i++)
{
int x,y;
cin >> x >>y;
a.push_back({x,y});
}
sort(a.begin(),a.end());
merge();
cout << b.size();
return 0;
}