結果
問題 | No.2294 Union Path Query (Easy) |
ユーザー | Ecrade_ |
提出日時 | 2023-05-05 23:01:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 484 ms / 4,000 ms |
コード長 | 2,136 bytes |
コンパイル時間 | 1,996 ms |
コンパイル使用メモリ | 170,580 KB |
実行使用メモリ | 144,076 KB |
最終ジャッジ日時 | 2024-11-23 11:12:02 |
合計ジャッジ時間 | 16,435 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 208 ms
143,232 KB |
testcase_04 | AC | 158 ms
83,968 KB |
testcase_05 | AC | 117 ms
73,984 KB |
testcase_06 | AC | 204 ms
143,232 KB |
testcase_07 | AC | 202 ms
144,076 KB |
testcase_08 | AC | 188 ms
140,416 KB |
testcase_09 | AC | 185 ms
140,672 KB |
testcase_10 | AC | 207 ms
143,232 KB |
testcase_11 | AC | 211 ms
143,176 KB |
testcase_12 | AC | 209 ms
143,104 KB |
testcase_13 | AC | 196 ms
141,952 KB |
testcase_14 | AC | 163 ms
136,576 KB |
testcase_15 | AC | 183 ms
142,592 KB |
testcase_16 | AC | 181 ms
135,680 KB |
testcase_17 | AC | 484 ms
141,824 KB |
testcase_18 | AC | 453 ms
141,056 KB |
testcase_19 | AC | 369 ms
139,392 KB |
testcase_20 | AC | 312 ms
138,496 KB |
testcase_21 | AC | 317 ms
140,416 KB |
testcase_22 | AC | 389 ms
141,824 KB |
testcase_23 | AC | 396 ms
141,824 KB |
testcase_24 | AC | 373 ms
139,648 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 56 ms
10,752 KB |
testcase_29 | AC | 65 ms
17,792 KB |
testcase_30 | AC | 73 ms
24,704 KB |
testcase_31 | AC | 80 ms
31,616 KB |
testcase_32 | AC | 89 ms
38,912 KB |
testcase_33 | AC | 97 ms
45,824 KB |
testcase_34 | AC | 102 ms
52,736 KB |
testcase_35 | AC | 108 ms
59,520 KB |
testcase_36 | AC | 114 ms
66,688 KB |
testcase_37 | AC | 126 ms
73,600 KB |
testcase_38 | AC | 131 ms
80,640 KB |
testcase_39 | AC | 140 ms
87,296 KB |
testcase_40 | AC | 149 ms
94,208 KB |
testcase_41 | AC | 159 ms
101,120 KB |
testcase_42 | AC | 167 ms
107,904 KB |
testcase_43 | AC | 175 ms
114,560 KB |
testcase_44 | AC | 178 ms
121,344 KB |
testcase_45 | AC | 193 ms
128,128 KB |
testcase_46 | AC | 197 ms
134,912 KB |
testcase_47 | AC | 218 ms
141,824 KB |
testcase_48 | AC | 179 ms
142,848 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 998244353; ll t = 1,n,m,k,q,l,r,a,b,c,u,v,x,y,z,o,X,hd[200009],tot,cnt[200009][39][2],rt[200009],id[200009],sz[200009],dis[200009],ans[200009]; string s; struct st{ll x,y,z; /*bool operator < (const st &a) const{return x < a.x;};*/}eg[400009]; void addedge(ll u,ll v,ll w){eg[++ tot] = (st){v,hd[u],w},hd[u] = tot;} bool cmp(const st &a,const st &b){return a.x < b.x;} inline ll read(){ ll s = 0,w = 1; char ch = getchar(); while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();} while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar(); return s * w; } ll qp(ll x,ll y){ ll a = 1,b = x; while (y){ if (y & 1) a = a * b % mod; b = b * b % mod,y >>= 1; } return a; } inline void add(ll &x,ll y){x += y; if (x >= mod) x -= mod;} ll find(ll x){return x == id[x] ? x : id[x] = find(id[x]);} void dfs(ll u,ll fa,ll rt){ for (ll i = 0;i < 30;i += 1) add(ans[rt],cnt[rt][i][((dis[u] >> i) & 1) ^ 1] * (1ll << i) % mod); for (ll i = 0;i < 30;i += 1) cnt[rt][i][(dis[u] >> i) & 1] += 1; for (ll i = hd[u];i;i = eg[i].y){ ll v = eg[i].x; if (v == fa) continue; dis[v] = dis[u] ^ eg[i].z,dfs(v,u,rt); } } void merge(ll x,ll y,ll z){ ll qwq = find(x),awa = find(y); if (qwq == awa) return; if (sz[qwq] > sz[awa]) swap(x,y),swap(qwq,awa); id[qwq] = awa,sz[awa] += sz[qwq],sz[qwq] = 0; dis[x] = dis[y] ^ z,addedge(x,y,z),addedge(y,x,z),dfs(x,y,awa); } ll query(ll x,ll y){ return dis[x] ^ dis[y]; } int main(){//t = read(); while (t --){ n = read(),X = read() + 1,q = read(); for (ll i = 1;i <= n;i += 1){ rt[i] = id[i] = i,sz[i] = 1; for (ll j = 0;j < 30;j += 1) cnt[i][j][0] = 1; } while (q --){ o = read(); if (o == 1){ x = read() + 1,y = read(); merge(x,X,y); } if (o == 2){ x = read() + 1,y = read() + 1; if (find(x) != find(y)) puts("-1"); else{ ll qwq = query(x,y); X += qwq; printf("%lld\n",qwq); } } if (o == 3){ x = read() + 1; printf("%lld\n",ans[find(x)]); } if (o == 4) X += read(); X = (X + n - 1) % n + 1; } } return 0; }