結果

問題 No.2292 Interval Union Find
ユーザー t98slidert98slider
提出日時 2023-02-11 09:12:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,808 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 175,812 KB
実行使用メモリ 12,972 KB
最終ジャッジ日時 2023-10-22 01:04:25
合計ジャッジ時間 9,362 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 54 ms
4,348 KB
testcase_05 AC 86 ms
4,348 KB
testcase_06 AC 55 ms
4,348 KB
testcase_07 AC 76 ms
4,348 KB
testcase_08 AC 85 ms
4,348 KB
testcase_09 AC 82 ms
4,348 KB
testcase_10 AC 74 ms
4,348 KB
testcase_11 AC 72 ms
4,348 KB
testcase_12 AC 88 ms
4,348 KB
testcase_13 AC 64 ms
4,348 KB
testcase_14 AC 67 ms
4,348 KB
testcase_15 AC 70 ms
4,348 KB
testcase_16 AC 67 ms
4,348 KB
testcase_17 AC 80 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 170 ms
12,960 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
        }
    }
}
0