void merge(vector<pair<int, int>> &segs)//合并segs中所有有交集的区间
{
vector<pair<int, int>> res;
sort(segs.begin(), segs.end());
int l = -2e9, r = -2e9;
for (auto seg : segs)
{
if (r < seg.first)
{
if (l != -2e9)
{
res.push_back({l, r});
}
l = seg.first, r = seg.second;
}
else
{
r = max(r, seg.second);
}
}
if (l != -2e9)
{
res.push_back({l, r});
}
segs = res;
}