题目描述
解题代码
#include
#include
using namespace std;
typedef pair PII;
const int N=1e5+10;
vector a,b;
int n;
void merge()
{
int st=-2e9,ed=-2e9;
for(auto t:a)
{
//结尾小于下一个段的开始新开一段
if(ed
//把上一段放入,排除初始状况
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
int x,y;
cin >> x >>y;
a.push_back({x,y});
}
sort(a.begin(),a.end());
merge();
cout << b.size();
return 0;
}