用 set 惨淡爆零,调了好久找不到原因

P2161 [SHOI2009] 会场预约

@[Roshin](/user/392696) 代码如下: ```c++ #include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> PII; typedef std::pair<ll, ll> PLL; typedef double db; #define arr(x) (x).begin(),(x).end() #define fi first #define se second #define pb push_back #define endl "\n" using namespace std; /*----------------------------------------------------------------------------------------------------*/ const int INF = 1e9; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int m; cin >> m; set<PII> sl, sr; sl.insert({INF, INF}); sr.insert({INF, INF}); while (m--) { string op; int l, r; cin >> op; if (op == "A") { cin >> l >> r; auto it = sl.lower_bound({l, -INF}); int cnt = 0; while (it->first <= r) { auto [dl, dr] = *it; auto ne = next(it); sl.erase(it); sr.erase(sr.find({dr, dl})); cnt++; it = ne; } it = sr.lower_bound({l, -INF}); while (it->first <= r) { auto [dl, dr] = *it; auto ne = next(it); sr.erase(it); sl.erase(sl.find({dr, dl})); cnt++; it = ne; } cout << cnt << endl; sl.insert({l, r}); sr.insert({r, l}); // for (auto t: sr) { // cout << t << " "; // } // cout << endl; } else { cout << sl.size() - 1<< endl; } } return 0; } ```
by Roshin @ 2022-07-17 14:24:48


@[Roshin](/user/392696) 没考虑包含
by Z_301 @ 2022-09-07 13:34:06


@[Z_301](/user/175087) soga,懂了谢谢!
by Roshin @ 2022-09-07 14:51:09


|