用 set维护区间即可,易得答案为最大区间长度加一。注意用 set.lower_bound() 加速寻找。 #include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int q; std::cin >> q; std::set<std::pair<int, int>> set; int ans = 1; while (q--) { int l, r; std::cin >> l >> r; i...