1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| void merge(vector<PII> &segs) { vector<PII> res;
sort(segs.begin(), segs.end());
int st = -2e9, ed = -2e9; for (auto seg : segs) { if (ed < seg.first) { if (st != -2e9) res.push_back({st, ed}); st = seg.first, ed = seg.second; } else ed = max(ed, seg.second);
} if (st != -2e9) res.push_back({st, ed}); segs = res; }
|