結果

問題 No.2294 Union Path Query (Easy)
ユーザー t98slidert98slider
提出日時 2023-02-09 06:01:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,928 bytes
コンパイル時間 4,376 ms
コンパイル使用メモリ 231,012 KB
実行使用メモリ 52,684 KB
最終ジャッジ日時 2023-08-14 15:10:35
合計ジャッジ時間 16,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 198 ms
52,340 KB
testcase_07 AC 197 ms
52,444 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 195 ms
52,432 KB
testcase_11 AC 200 ms
52,448 KB
testcase_12 AC 194 ms
52,596 KB
testcase_13 WA -
testcase_14 AC 152 ms
52,148 KB
testcase_15 AC 181 ms
52,512 KB
testcase_16 AC 143 ms
52,460 KB
testcase_17 AC 170 ms
52,500 KB
testcase_18 AC 164 ms
52,496 KB
testcase_19 AC 167 ms
52,528 KB
testcase_20 AC 157 ms
52,440 KB
testcase_21 AC 161 ms
52,448 KB
testcase_22 WA -
testcase_23 AC 163 ms
52,472 KB
testcase_24 AC 158 ms
52,684 KB
testcase_25 AC 1 ms
4,944 KB
testcase_26 AC 1 ms
4,944 KB
testcase_27 AC 1 ms
4,944 KB
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 -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, X, Q;
    cin >> N >> X >> Q;

    vector<int> parent_or_size(N, -1), difference_weight(N);
    vector<array<array<mint, 2>, 30>> cnt(N);
    vector<mint> ans(N);

    function<int(int)> leader = [&](int v){
        if (parent_or_size[v] < 0) return v;
        int root = leader(parent_or_size[v]);
        difference_weight[v] ^= difference_weight[parent_or_size[v]];
        return parent_or_size[v] = root;
    };

    auto merge = [&](int u, int v, int w){
        int x = leader(u), y = leader(v);
        w ^= difference_weight[u], w ^= difference_weight[v];
        if (-parent_or_size[x] < -parent_or_size[y]) swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        ans[x] = 0;
        for(int i = 0; i < 30; i++){
            for(int j = 0; j < 2; j++){
                cnt[x][i][j ^ (w >> i & 1)] += cnt[y][x][j];
            }
            ans[x] += cnt[x][i][0] * cnt[x][i][1] * (1 << i);
        }
        difference_weight[y] = w;
    };

    auto distance = [&](int u, int v){
        int x = leader(u), y = leader(v);
        if(x != y) return -1;
        return difference_weight[v] ^ difference_weight[u];
    };


    for(int i = 0; i < N; i++){
        for(int j = 0; j < 30; j++) cnt[i][j][0]++;
    }

    while(Q--){
        int type, u, v, w;
        cin >> type;
        if(type == 1){
            cin >> v >> w;
            merge(v, X, w);
        }else if(type == 2){
            cin >> u >> v;
            v = distance(u, v);
            cout << v << '\n';
            if(v != -1) (X += v) %= N;
        }else if(type == 3){
            cin >> v;
            cout << ans[leader(v)].val() << '\n';
        }else{
            cin >> v;
            (X += v) %= N;
        }
    }
}
0