結果

問題 No.1641 Tree Xor Query
ユーザー 👑 tamatotamato
提出日時 2021-08-06 22:05:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 260 ms / 5,000 ms
コード長 2,292 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 116,880 KB
最終ジャッジ日時 2023-10-17 03:27:49
合計ジャッジ時間 3,614 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,680 KB
testcase_01 AC 40 ms
55,680 KB
testcase_02 AC 41 ms
55,680 KB
testcase_03 AC 41 ms
55,680 KB
testcase_04 AC 42 ms
55,680 KB
testcase_05 AC 42 ms
55,680 KB
testcase_06 AC 41 ms
55,680 KB
testcase_07 AC 42 ms
55,680 KB
testcase_08 AC 41 ms
55,680 KB
testcase_09 AC 41 ms
55,680 KB
testcase_10 AC 41 ms
55,680 KB
testcase_11 AC 42 ms
55,680 KB
testcase_12 AC 40 ms
55,680 KB
testcase_13 AC 260 ms
114,720 KB
testcase_14 AC 259 ms
114,764 KB
testcase_15 AC 87 ms
77,236 KB
testcase_16 AC 114 ms
78,716 KB
testcase_17 AC 112 ms
77,924 KB
testcase_18 AC 99 ms
77,764 KB
testcase_19 AC 84 ms
76,588 KB
testcase_20 AC 229 ms
116,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0