結果
問題 | No.2294 Union Path Query (Easy) |
ユーザー | milanis48663220 |
提出日時 | 2023-05-05 23:23:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 464 ms / 4,000 ms |
コード長 | 3,771 bytes |
コンパイル時間 | 2,184 ms |
コンパイル使用メモリ | 127,736 KB |
実行使用メモリ | 54,204 KB |
最終ジャッジ日時 | 2023-08-15 06:38:03 |
合計ジャッジ時間 | 25,313 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 346 ms
46,284 KB |
testcase_04 | AC | 372 ms
27,852 KB |
testcase_05 | AC | 383 ms
24,880 KB |
testcase_06 | AC | 330 ms
46,276 KB |
testcase_07 | AC | 309 ms
46,344 KB |
testcase_08 | AC | 392 ms
46,412 KB |
testcase_09 | AC | 393 ms
46,412 KB |
testcase_10 | AC | 336 ms
46,412 KB |
testcase_11 | AC | 338 ms
46,292 KB |
testcase_12 | AC | 331 ms
46,276 KB |
testcase_13 | AC | 366 ms
46,568 KB |
testcase_14 | AC | 371 ms
46,080 KB |
testcase_15 | AC | 290 ms
46,636 KB |
testcase_16 | AC | 464 ms
46,224 KB |
testcase_17 | AC | 368 ms
54,204 KB |
testcase_18 | AC | 396 ms
53,292 KB |
testcase_19 | AC | 405 ms
50,808 KB |
testcase_20 | AC | 424 ms
49,620 KB |
testcase_21 | AC | 438 ms
49,504 KB |
testcase_22 | AC | 434 ms
50,824 KB |
testcase_23 | AC | 434 ms
50,924 KB |
testcase_24 | AC | 426 ms
50,916 KB |
testcase_25 | AC | 1 ms
4,380 KB |
testcase_26 | AC | 2 ms
4,380 KB |
testcase_27 | AC | 1 ms
4,380 KB |
testcase_28 | AC | 425 ms
5,396 KB |
testcase_29 | AC | 436 ms
7,888 KB |
testcase_30 | AC | 437 ms
9,660 KB |
testcase_31 | AC | 413 ms
11,944 KB |
testcase_32 | AC | 432 ms
14,264 KB |
testcase_33 | AC | 418 ms
16,156 KB |
testcase_34 | AC | 405 ms
18,808 KB |
testcase_35 | AC | 406 ms
20,916 KB |
testcase_36 | AC | 405 ms
22,820 KB |
testcase_37 | AC | 399 ms
24,796 KB |
testcase_38 | AC | 403 ms
27,044 KB |
testcase_39 | AC | 406 ms
29,080 KB |
testcase_40 | AC | 399 ms
31,284 KB |
testcase_41 | AC | 396 ms
33,400 KB |
testcase_42 | AC | 388 ms
35,412 KB |
testcase_43 | AC | 391 ms
37,596 KB |
testcase_44 | AC | 389 ms
40,132 KB |
testcase_45 | AC | 394 ms
42,128 KB |
testcase_46 | AC | 391 ms
44,304 KB |
testcase_47 | AC | 387 ms
46,576 KB |
testcase_48 | AC | 238 ms
46,620 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/modint> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, x, q; cin >> n >> x >> q; UnionFind uf(n); vector<int> xo(n); auto cnt = vec2d(n, 30, 0); vector<vector<int>> components(n); for(int i = 0; i < n; i++) components[i].push_back(i); while(q--){ int t; cin >> t; // debug_value(t) // debug_value(x) // print_vector(xo); if(t == 1){ int u, w; cin >> u >> w; int us = uf.size(u); int ux = uf.size(x); int cur_xor = xo[u]^xo[x]; int diff = cur_xor^w; int rx = ux > us ? uf.root(x) : uf.root(u); int ru = ux > us ? uf.root(u) : uf.root(x); for(int v: components[ru]){ xo[v] ^= diff; for(int j = 0; j < 30; j++){ if(xo[v]&(1<<j)){ cnt[rx][j]++; } } components[rx].push_back(v); } uf.unionSet(u, x); int r = uf.root(u); cnt[r] = cnt[rx]; components[r] = components[rx]; components[ru].clear(); }else if(t == 2){ int u, v; cin >> u >> v; if(uf.findSet(u, v)){ int dist = xo[u]^xo[v]; cout << dist << endl; x = (x+dist)%n; }else{ cout << -1 << endl; } }else if(t == 3){ int v; cin >> v; int r = uf.root(v); mint ans = 0; int m = uf.size(r); for(int j = 0; j < 30; j++){ int c1 = cnt[r][j]; int c0 = m-c1; ans += mint(1<<j)*mint(c0)*mint(c1); } cout << ans << endl; }else{ int v; cin >> v; x = (x+v)%n; } } }