結果
問題 |
No.2292 Interval Union Find
|
ユーザー |
![]() |
提出日時 | 2023-05-05 22:05:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,126 bytes |
コンパイル時間 | 2,106 ms |
コンパイル使用メモリ | 177,560 KB |
実行使用メモリ | 22,272 KB |
最終ジャッジ日時 | 2024-11-23 07:52:17 |
合計ジャッジ時間 | 25,874 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 WA * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, Q; cin >> N >> Q; map<int, int> mp; mp[0] = 0; mp[N + 1] = 0; for (int i = 0; i < Q; i++){ int t; cin >> t; if (t == 1){ int L, R; cin >> L >> R; for (int j : {L, R}){ if (mp.count(j) == 0){ auto itr = prev(mp.lower_bound(j)); int x = (*itr).second; mp[j] = x; } } while (true){ auto itr = mp.lower_bound(L); int p1 = (*itr).first; if (p1 == R){ break; } mp.erase(itr); } mp[L] = 1; for (int j : {L, R}){ auto itr = mp.lower_bound(j); if ((*itr).second == (*prev(itr)).second){ mp.erase(itr); } } } if (t == 2){ int L, R; cin >> L >> R; for (int j : {L, R}){ if (mp.count(j) == 0){ auto itr = prev(mp.lower_bound(j)); int x = (*itr).second; mp[j] = x; } } while (true){ auto itr = mp.lower_bound(L); int p1 = (*itr).first; if (p1 == R){ break; } mp.erase(itr); } mp[L] = 0; for (int j : {L, R}){ auto itr = mp.lower_bound(j); if ((*itr).second == (*prev(itr)).second){ mp.erase(itr); } } } if (t == 3){ int u, v; cin >> u >> v; if (u == v){ cout << 1 << endl; } else { if (u > v){ swap(u, v); } v--; auto itr = prev(mp.upper_bound(u)); if ((*itr).second == 1 && (*next(itr)).first >= v){ cout << 1 << endl; } else { cout << 0 << endl; } } } if (t == 4){ int v; cin >> v; auto itr = prev(mp.lower_bound(v)); if ((*itr).second == 0){ if ((*next(itr)).first == v){ cout << (*next(itr, 2)).first - (*next(itr)).first + 1 << endl; } else { cout << 1 << endl; } } else { cout << (*next(itr)).first - (*itr).first + 1 << endl; } } } }