結果

問題 No.2292 Interval Union Find
ユーザー t98slidert98slider
提出日時 2023-02-15 14:07:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,894 bytes
コンパイル時間 5,130 ms
コンパイル使用メモリ 176,640 KB
実行使用メモリ 12,956 KB
最終ジャッジ日時 2023-10-22 01:04:40
合計ジャッジ時間 13,565 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 62 ms
4,348 KB
testcase_05 AC 98 ms
4,348 KB
testcase_06 AC 62 ms
4,348 KB
testcase_07 AC 93 ms
4,348 KB
testcase_08 AC 95 ms
4,348 KB
testcase_09 AC 95 ms
4,348 KB
testcase_10 AC 84 ms
4,348 KB
testcase_11 AC 79 ms
4,348 KB
testcase_12 AC 98 ms
4,348 KB
testcase_13 AC 74 ms
4,348 KB
testcase_14 AC 75 ms
4,348 KB
testcase_15 AC 79 ms
4,348 KB
testcase_16 AC 76 ms
4,348 KB
testcase_17 AC 92 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 229 ms
12,956 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;

struct Problem_D{
    set<pair<int,int>> S;
    Problem_D(int N) {
        S.insert({N + 1, N + 1});
    }
    void insert(int L, int R){
        int l, r;
        auto it = S.lower_bound({L, -1});
        while(it->second <= R){
            tie(r, l) = *it;
            S.erase(it);
            L = min(L, l);
            R = max(R, r);
            it = S.lower_bound({L, -1});
        }
        S.insert({R, L});
    }
    void erase(int L, int R){
        int l, r;
        auto it = S.lower_bound({L + 1, -1});
        while(it->second < R){
            tie(r, l) = *it;
            S.erase(it);
            if(l < L) S.insert({L, l});
            if(R < r) S.insert({r, R});
            it = S.lower_bound({L + 1, -1});
        }
    }
    int size(int v){
        auto it = S.lower_bound({v, -1});
        if(it->second <= v && v <= it->first) return it->first - it->second + 1;
        return 1;
    }
    bool same(int v, int u){
        if(u < v) swap(u, v);
        auto it = S.lower_bound({v, -1});
        return (it->second <= v && u <= it->first);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;

    assert(2 <= N && N <= 1000000000);
    assert(1 <= Q && Q <= 200000);

    Problem_D uf(N);

    int type, L, R, v, u;
    while(Q--){
        cin >> type;
        if(type <= 2){
            cin >> L >> R;
            assert(1 <= L && L <= N);
            assert(1 <= R && R <= N);
            if(type == 1) uf.insert(L, R);
            else uf.erase(L, R);
        }else if(type == 3){
            cin >> u >> v;
            assert(1 <= u && u <= N);
            assert(1 <= v && v <= N);
            cout << (uf.same(u, v) ? 1 : 0) << '\n';
        }else{
            cin >> v;
            assert(1 <= v && v <= N);
            cout << uf.size(v) << '\n';
        }
    }
}
0