結果
問題 | No.1641 Tree Xor Query |
ユーザー | rlangevin |
提出日時 | 2023-02-22 00:12:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 309 ms / 5,000 ms |
コード長 | 2,023 bytes |
コンパイル時間 | 450 ms |
コンパイル使用メモリ | 87,152 KB |
実行使用メモリ | 118,112 KB |
最終ジャッジ日時 | 2023-09-29 13:03:02 |
合計ジャッジ時間 | 4,842 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
75,424 KB |
testcase_01 | AC | 75 ms
75,272 KB |
testcase_02 | AC | 71 ms
75,492 KB |
testcase_03 | AC | 72 ms
75,488 KB |
testcase_04 | AC | 74 ms
79,940 KB |
testcase_05 | AC | 74 ms
79,920 KB |
testcase_06 | AC | 76 ms
79,768 KB |
testcase_07 | AC | 74 ms
79,812 KB |
testcase_08 | AC | 72 ms
75,464 KB |
testcase_09 | AC | 75 ms
79,940 KB |
testcase_10 | AC | 75 ms
80,044 KB |
testcase_11 | AC | 72 ms
75,420 KB |
testcase_12 | AC | 72 ms
75,460 KB |
testcase_13 | AC | 309 ms
115,764 KB |
testcase_14 | AC | 294 ms
115,816 KB |
testcase_15 | AC | 109 ms
82,712 KB |
testcase_16 | AC | 148 ms
84,140 KB |
testcase_17 | AC | 146 ms
83,468 KB |
testcase_18 | AC | 120 ms
83,032 KB |
testcase_19 | AC | 127 ms
82,432 KB |
testcase_20 | AC | 256 ms
118,112 KB |
ソースコード
import sys readline = sys.stdin.readline class SegmentTree: def __init__(self, size, f=lambda x, y: x^y, default=0): self.size = 2**(size-1).bit_length() self.default = default self.dat = [default]*(self.size*2) self.f = f def update(self, i, x): i += self.size self.dat[i] = x while i > 0: i >>= 1 self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1]) def query(self, l, r): l += self.size r += self.size lres, rres = self.default, self.default while l < r: if l & 1: lres = self.f(lres, self.dat[l]) l += 1 if r & 1: r -= 1 rres = self.f(self.dat[r], rres) l >>= 1 r >>= 1 res = self.f(lres, rres) return res def non_rec_dfs(s): stack = [] stack.append(~s) stack.append(s) euler_tour = [] discovery = [-1] * N finishing = [-1] * N now = 0 par = [-1] * N while stack: u = stack.pop() if u >= 0: stack.append(~u) discovery[u] = now euler_tour.append(u) for v in G[u]: if v == par[u]: continue par[v] = u stack.append(v) else: u = ~u finishing[u] = now euler_tour.append(u) now += 1 return discovery, finishing, euler_tour N, Q = map(int, readline().split()) C = list(map(int, readline().split())) G = [[] for i in range(N)] for i in range(N - 1): A, B = map(int, readline().split()) A, B = A - 1, B - 1 G[A].append(B) G[B].append(A) D, F, _ = non_rec_dfs(0) T = SegmentTree(202020) for i in range(N): T.update(D[i], C[i]) for _ in range(Q): t, x, y = map(int, readline().split()) x -= 1 if t == 1: C[x] ^= y T.update(D[x], C[x]) else: print(T.query(D[x], F[x] + 1))