Loading... ## 样例输入 ``` 5 5 6 1 5 10 10 6 9 8 10 ``` ## 样例输出 ``` 1 10 ``` ## AC ```cpp #include <bits/stdc++.h> #define x first #define y second using namespace std; const int N = 1e5 + 10; int n; typedef pair<int, int> PII; vector<PII> segs; vector<PII> res; int main() { cin >> n; int a, b; for (int i = 1; i <= n; i++) { cin >> a >> b; segs.push_back({a, b}); } sort(segs.begin(), segs.end()); int l = -2e9, r = -2e9; for (auto i : segs) { if (r < i.x) { if (l != -2e9) res.push_back({l, r}); l = i.x, r = i.y; } else r = max(r, i.y); } if (l != -2e9) res.push_back({l, r}); for (auto i : res) cout << i.x << " " << i.y << endl; return 0; } ``` Last modification:March 25, 2023 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed