This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>
usingnamespacestd;
constintN=1e5+10;
constintINF=0x3f3f3f3f;
intn;// 线段数量
intres;// 结果
inted=-INF;// 当前覆盖区间的结束边界,即右端点位置
// 结构体
structNode{
intl,r;
// 按每个区间的右端点从小到大排序
constbooloperator<(constNode&b)const{
returnr<b.r;
}
}range[N];
intmain(){
cin>>n;
// 注意这里的数组下标是从0开始的
for(inti=0;i<n;i++)cin>>range[i].l>>range[i].r;
// 右端点从小到大排序,排序也需要从数组下标1开始
sort(range,range+n);
// 思想:① 所有区间按右端点从小到大排序
// ② 遍历每一个区间,如果当前区间的左与前一个区间的右有交集,则只需要一个点就可以覆盖掉两个区间