区间合并。
作者:互联网
// 将所有存在交集的区间合并
void Merge(vector<PII>& segs)
{
sort(segs.begin(), segs.end());
vector<PII> ans;
int st = -2e9, ed = -2e9;
for(auto& seg : segs)
{
if (ed < seg.first)
{
if (st != -2e9) ans.push_back({st, ed});
st = seg.first, ed = seg.second;
}
else ed = max(ed, seg.second);
}
if (st != -2e9) ans.push_back({st, ed});
segs = ans;
}
标签:2e9,ed,合并,segs,st,seg,ans,区间 来源: https://blog.csdn.net/m0_46106615/article/details/121360036