結果
| 問題 |
No.2292 Interval Union Find
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-11 09:12:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,808 bytes |
| コンパイル時間 | 1,815 ms |
| コンパイル使用メモリ | 175,700 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2024-09-22 02:25:04 |
| 合計ジャッジ時間 | 10,520 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 15 WA * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N, Q;
cin >> N >> Q;
set<pair<int,int>> S;
S.insert({N + 1, N + 1});
auto add = [&](int l, int r){
auto it = S.lower_bound({l, -1});
if(it->second <= l && r <= it->first)return;
while(it->second <= r){
l = min(l, it->second);
r = max(r, it->first);
S.erase(it);
it = S.lower_bound({l, -1});
}
S.insert({r, l});
};
auto del = [&](int l, int r){
auto it = S.lower_bound({l + 1, -1});
while(it->second < r){
int l0, r0, l1, r1;
tie(r0, l0) = *it;
l1 = l0, r1 = r0;
S.erase(it);
l0 = min(l0, l);
r0 = min(r0, l);
l1 = max(l1, r);
r1 = max(r1, r);
if(l0 < r0) S.insert({r0, l0});
if(l1 < r1) S.insert({r1, l1});
it = S.lower_bound({l + 1, -1});
}
};
auto same = [&](int l, int r){
if(l > r) swap(l, r);
auto it = S.lower_bound({l, -1});
if(it->second <= l && r <= it->first) return true;
return false;
};
auto size = [&](int v){
auto it = S.lower_bound({v, -1});
if(it->second <= v && v <= it->first) return int(it->first - it->second + 1);
return 1;
};
int type, L, R, u, v;
while(Q--){
cin >> type;
if(type <= 2){
cin >> L >> R;
if(type == 1) add(L, R);
else del(L, R);
}else if(type == 3){
cin >> u >> v;
cout << (same(u, v) ? 1 : 0) << '\n';
}else{
cin >> v;
cout << size(v) << '\n';
}
}
}