結果
| 問題 |
No.2292 Interval Union Find
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-11 03:10:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,271 bytes |
| コンパイル時間 | 1,686 ms |
| コンパイル使用メモリ | 173,396 KB |
| 実行使用メモリ | 12,928 KB |
| 最終ジャッジ日時 | 2024-09-22 02:24:48 |
| 合計ジャッジ時間 | 15,029 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | AC * 1 WA * 37 TLE * 1 -- * 5 |
ソースコード
#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 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 == 1){
cin >> L >> R;
add(L, R);
}else if(type == 2){
cin >> u >> v;
cout << (same(u, v) ? 1 : 0) << '\n';
}else{
cin >> v;
cout << size(v) << '\n';
}
}
}