結果
問題 | No.1641 Tree Xor Query |
ユーザー | Kude |
提出日時 | 2021-08-06 22:22:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 102 ms / 5,000 ms |
コード長 | 4,071 bytes |
コンパイル時間 | 4,589 ms |
コンパイル使用メモリ | 260,280 KB |
最終ジャッジ日時 | 2025-01-23 15:45:49 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
In member function ‘void HLD::assign_idx(int, int, int&, int)’, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23: main.cpp:57:19: warning: ‘mi’ may be used uninitialized [-Wmaybe-uninitialized] 57 | assign_idx(mi, h, nxt, u); | ~~~~~~~~~~^~~~~~~~~~~~~~~ main.cpp: In member function ‘void HLD::assign_idx(int, int, int&, int)’: main.cpp:49:13: note: ‘mi’ was declared here 49 | int mi; | ^~ In member function ‘void HLD::assign_idx(int, int, int&, int)’, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23: main.cpp:57:19: warning: ‘mi’ may be used uninitialized [-Wmaybe-uninitialized] 57 | assign_idx(mi, h, nxt, u); | ~~~~~~~~~~^~~~~~~~~~~~~~~ main.cpp: In member function ‘void HLD::assign_idx(int, int, int&, int)’: main.cpp:49:13: note: ‘mi’ was declared here 49 | int mi; | ^~ In member function ‘void HLD::assign_idx(int, int, int&, int)’, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:57:19, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23: main.cpp:57:19: warning: ‘mi’ may be used uninitialized [-Wmaybe-uninitialized] 57 | assign_idx(mi, h, nxt, u); | ~~~~~~~~~~^~~~~~~~~~~~~~~ main.cpp: In member function ‘void HLD::assign_idx(int, int, int&, int)’: main.cpp:49:13: note: ‘mi’ was declared here 49 | int mi; | ^~ In member function ‘void HLD::assign_idx(int, int, int&, int)’, inlined from ‘void HLD::assign_idx(int, int, int&, int)’ at main.cpp:60:23, inlined from ‘void HL
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template<class T> void chmax(T& a, const T& b) {a = max(a, b);} template<class T> void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; struct HLD { std::vector<std::vector<int>> &to; int root, n; std::vector<int> sz, parent, depth, idx, ridx, head, inv; HLD(std::vector<std::vector<int>>& to, int root=0): to(to), root(root), n(to.size()), sz(n), parent(n), depth(n), idx(n), ridx(n), head(n), inv(n) { init_tree_data(root); int x = 0; assign_idx(root, root, x); } void init_tree_data(int u, int p=-1, int d=0) { parent[u] = p; depth[u] = d; int s = 1; for(int v: to[u]) { if (v == p) continue; init_tree_data(v, u, d+1); s += sz[v]; } sz[u] = s; } void assign_idx(int u, int h, int &nxt, int p=-1) { head[u] = h; inv[nxt] = u; idx[u] = nxt++; if (sz[u] == 1) { ridx[u] = nxt; return; } int mxsize = 0; int mi; for(int v: to[u]) { if (v == p) continue; if (sz[v] > mxsize) { mxsize = sz[v]; mi = v; } } assign_idx(mi, h, nxt, u); for(int v: to[u]) { if (v == p || v == mi) continue; assign_idx(v, v, nxt, u); } ridx[u] = nxt; } int lca(int u, int v) { while(head[u] != head[v]) { if (depth[head[u]] > depth[head[v]]) u = parent[head[u]]; else v = parent[head[v]]; } return (depth[u] < depth[v] ? u : v); } // returns (paths upto lca from x (excluding lca), those from y, lca) std::tuple<std::vector<std::pair<int, int>>, std::vector<std::pair<int, int>>, int> paths(int x, int y) { std::tuple<std::vector<std::pair<int, int>>, std::vector<std::pair<int, int>>, int> ret; std::vector<std::pair<int, int>>& x_paths = get<0>(ret); std::vector<std::pair<int, int>>& y_paths = get<1>(ret); int& lca = get<2>(ret); while(head[x] != head[y]) { int xhead = head[x], yhead = head[y]; if (depth[xhead] > depth[yhead]) { x_paths.emplace_back(x, xhead); x = parent[xhead]; } else { y_paths.emplace_back(y, yhead); y = parent[yhead]; } } if (depth[x] > depth[y]) { int ychild = inv[idx[y] + 1]; x_paths.emplace_back(x, ychild); x = y; } else if (depth[x] < depth[y]) { int xchild = inv[idx[x] + 1]; y_paths.emplace_back(y, xchild); y = x; } lca = x; return ret; } int dist(int u, int v) { int w = lca(u, v); return depth[u] + depth[v] - 2 * depth[w]; } }; int op(int x, int y) {return x ^ y;} int e() {return 0;} int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; VI c_orig(n); rep(i, n) cin >> c_orig[i]; VVI to(n); rep(_, n - 1) { int a, b; cin >> a >> b; a--, b--; to[a].push_back(b); to[b].push_back(a); } HLD hld(to); VI c(n); rep(i, n) c[hld.idx[i]] = c_orig[i]; segtree<int, op, e> seg(c); while(q--) { int t, x, y; cin >> t >> x >> y; x--; if (t == 1) { int idx = hld.idx[x]; seg.set(idx, seg.get(idx) ^ y); } else { int ans = seg.prod(hld.idx[x], hld.ridx[x]); cout << ans << '\n'; } } }