区间合并。

// 将所有存在交集的区间合并
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;
}
上一篇:LeetCode:#907子数组的最小值之和


下一篇:ABC214 E-Packing Under Range Regulation(贪心)