結果
問題 | No.1641 Tree Xor Query |
ユーザー | carrot46 |
提出日時 | 2021-08-06 21:56:56 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 216 ms / 5,000 ms |
コード長 | 1,933 bytes |
コンパイル時間 | 2,293 ms |
コンパイル使用メモリ | 212,500 KB |
実行使用メモリ | 14,516 KB |
最終ジャッジ日時 | 2023-10-17 03:19:19 |
合計ジャッジ時間 | 3,976 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 216 ms
14,516 KB |
testcase_14 | AC | 213 ms
14,516 KB |
testcase_15 | AC | 4 ms
4,348 KB |
testcase_16 | AC | 11 ms
4,348 KB |
testcase_17 | AC | 8 ms
4,348 KB |
testcase_18 | AC | 6 ms
4,348 KB |
testcase_19 | AC | 7 ms
4,348 KB |
testcase_20 | AC | 131 ms
11,896 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/segtree> using namespace std; using namespace atcoder; //#pragma GCC optimize("Ofast") #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } using T = int; int op(int a, int b){ return a ^ b; } int e(){ return 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N>>Q; vec c(N), f(N), g(N); rep(i, N) cin>>c[i]; { mat G(N); rep(i, N - 1){ int a, b; cin>>a>>b; --a; --b; G[a].push_back(b); G[b].push_back(a); } int t{}; auto dfs = [&](auto &&self, int p, int v) -> void{ f[v] = t++; for(int to : G[v]) if(to != p) self(self, v, to); g[v] = t++; }; dfs(dfs, -1, 0); } segtree<T, op, e> seg(N * 2); auto add = [&](int p, T x){ seg.set(p, op(seg.get(p), x)); }; rep(i, N) add(f[i], c[i]); while(Q--){ int t, x, y; cin>>t>>x>>y; --x; if(t == 1){ add(f[x], y); }else{ cout<<seg.prod(f[x], g[x])<<endl; } } }