結果
問題 | No.1641 Tree Xor Query |
ユーザー | tamato |
提出日時 | 2021-08-06 22:05:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 285 ms / 5,000 ms |
コード長 | 2,292 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,032 KB |
実行使用メモリ | 117,316 KB |
最終ジャッジ日時 | 2024-09-17 02:04:41 |
合計ジャッジ時間 | 3,189 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,656 KB |
testcase_01 | AC | 44 ms
53,996 KB |
testcase_02 | AC | 43 ms
54,532 KB |
testcase_03 | AC | 44 ms
54,720 KB |
testcase_04 | AC | 45 ms
55,428 KB |
testcase_05 | AC | 45 ms
55,696 KB |
testcase_06 | AC | 44 ms
55,964 KB |
testcase_07 | AC | 45 ms
55,784 KB |
testcase_08 | AC | 43 ms
55,140 KB |
testcase_09 | AC | 44 ms
55,120 KB |
testcase_10 | AC | 44 ms
55,668 KB |
testcase_11 | AC | 43 ms
55,036 KB |
testcase_12 | AC | 43 ms
54,652 KB |
testcase_13 | AC | 285 ms
114,988 KB |
testcase_14 | AC | 279 ms
115,136 KB |
testcase_15 | AC | 91 ms
77,236 KB |
testcase_16 | AC | 119 ms
79,332 KB |
testcase_17 | AC | 116 ms
78,300 KB |
testcase_18 | AC | 103 ms
77,828 KB |
testcase_19 | AC | 89 ms
76,816 KB |
testcase_20 | AC | 250 ms
117,316 KB |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys from collections import deque input = sys.stdin.readline # adj[0] must be empty list def EulerTour(adj, root): st = [root] ret = [] seen = [0] * len(adj) par = [0] * len(adj) depth = [0] * len(adj) while st: v = st.pop() if seen[v]: ret.append(v) continue ret.append(v) seen[v] = 1 if par[v] != 0: st.append(par[v]) for u in adj[v]: if seen[u] == 0: st.append(u) par[u] = v depth[u] = depth[v] + 1 return ret, depth class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s ^= self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] ^= x i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 k = 1 << (self.size.bit_length() - 1) while k: if x + k <= self.size and self.tree[x + k] < w: w -= self.tree[x + k] x += k k >>= 1 return x + 1 N, Q = map(int, input().split()) C = [0] + list(map(int, input().split())) adj = [[] for _ in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) adj[a].append(b) adj[b].append(a) ET, depth = EulerTour(adj, 1) L = [-1] * (N+1) R = [-1] * (N+1) seen = [0] * (N+1) bit = Bit(len(ET)) for i, v in enumerate(ET): if not seen[v]: seen[v] = 1 L[v] = i+1 bit.add(i+1, C[v]) R[v] = i + 1 for _ in range(Q): t, x, y = map(int, input().split()) if t == 1: bit.add(L[x], y) else: ans = bit.sum(R[x]) if L[x] != 1: ans ^= bit.sum(L[x] - 1) print(ans) if __name__ == '__main__': main()