結果
問題 | No.2294 Union Path Query (Easy) |
ユーザー | t98slider |
提出日時 | 2023-02-10 18:12:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 249 ms / 4,000 ms |
コード長 | 1,928 bytes |
コンパイル時間 | 5,320 ms |
コンパイル使用メモリ | 233,180 KB |
実行使用メモリ | 52,608 KB |
最終ジャッジ日時 | 2024-05-02 03:15:21 |
合計ジャッジ時間 | 19,625 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 226 ms
52,480 KB |
testcase_04 | AC | 192 ms
31,360 KB |
testcase_05 | AC | 165 ms
28,032 KB |
testcase_06 | AC | 249 ms
52,480 KB |
testcase_07 | AC | 240 ms
52,352 KB |
testcase_08 | AC | 212 ms
52,480 KB |
testcase_09 | AC | 214 ms
52,480 KB |
testcase_10 | AC | 236 ms
52,480 KB |
testcase_11 | AC | 230 ms
52,608 KB |
testcase_12 | AC | 230 ms
52,480 KB |
testcase_13 | AC | 208 ms
52,480 KB |
testcase_14 | AC | 166 ms
52,352 KB |
testcase_15 | AC | 186 ms
52,480 KB |
testcase_16 | AC | 158 ms
52,480 KB |
testcase_17 | AC | 185 ms
52,352 KB |
testcase_18 | AC | 185 ms
52,480 KB |
testcase_19 | AC | 179 ms
52,352 KB |
testcase_20 | AC | 174 ms
52,480 KB |
testcase_21 | AC | 180 ms
52,480 KB |
testcase_22 | AC | 196 ms
52,480 KB |
testcase_23 | AC | 191 ms
52,480 KB |
testcase_24 | AC | 198 ms
52,480 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 88 ms
5,760 KB |
testcase_29 | AC | 101 ms
8,192 KB |
testcase_30 | AC | 108 ms
10,624 KB |
testcase_31 | AC | 111 ms
12,928 KB |
testcase_32 | AC | 117 ms
15,488 KB |
testcase_33 | AC | 124 ms
18,048 KB |
testcase_34 | AC | 131 ms
20,608 KB |
testcase_35 | AC | 140 ms
22,784 KB |
testcase_36 | AC | 146 ms
25,216 KB |
testcase_37 | AC | 158 ms
27,776 KB |
testcase_38 | AC | 177 ms
30,208 KB |
testcase_39 | AC | 176 ms
32,768 KB |
testcase_40 | AC | 178 ms
35,200 KB |
testcase_41 | AC | 183 ms
37,632 KB |
testcase_42 | AC | 188 ms
40,064 KB |
testcase_43 | AC | 187 ms
42,624 KB |
testcase_44 | AC | 195 ms
45,056 KB |
testcase_45 | AC | 223 ms
47,488 KB |
testcase_46 | AC | 218 ms
50,048 KB |
testcase_47 | AC | 215 ms
52,480 KB |
testcase_48 | AC | 172 ms
52,352 KB |
ソースコード
#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][i][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; } } }