CompetitiveProgramming/src/bin/cf-1884c.cc

56 lines
1.1 KiB
C++
Raw Normal View History

2024-01-18 04:40:12 +00:00
#include<bits/stdc++.h>
using namespace std;
2024-05-07 10:27:31 +01:00
2024-01-18 04:40:12 +00:00
void solve() {
int n, m; cin >> n >> m;
vector<pair<int, int>> seg(n);
for (int i = 0; i < n; ++i) {
int l, r; cin >> l >> r;
seg[i] = {l, r};
}
sort(seg.begin(), seg.end(), [](const pair<int, int>& x, const pair<int, int>& y) {
if (x.first == y.first) {
return x.second > y.second;
}
return x.first < y.first;
});
int res = 0;
set<pair<int, int>> lefts;
set<pair<int, int>> rights;
int prev = 0;
for (int i = 0; i < n; ++i) {
auto&& [l, r] = seg[i];
if (l == 1 || l == prev) continue;
prev = l;
auto rp = rights.begin();
while (rights.size() && rp->first < l) {
lefts.erase({seg[rp->second].first, rp->second});
rp = rights.erase(rp);
}
lefts.insert({l, i});
rights.insert({r, i});
res = max(res, int(lefts.size()));
cerr << lefts.size() << ' ' << res << endl;
}
lefts.clear(), rights.clear(), prev = 0;
cout << res << endl;
}
2024-05-07 10:27:31 +01:00
2024-01-18 04:40:12 +00:00
int main() {
int t; cin >> t;
while (t--) solve();
2024-05-07 10:27:31 +01:00
}