結果

問題 No.1641 Tree Xor Query
ユーザー tonyu0tonyu0
提出日時 2022-09-22 12:11:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,541 ms / 5,000 ms
コード長 1,183 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,084 KB
実行使用メモリ 58,256 KB
最終ジャッジ日時 2023-08-23 20:29:31
合計ジャッジ時間 8,780 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,100 KB
testcase_01 AC 16 ms
8,128 KB
testcase_02 AC 17 ms
8,204 KB
testcase_03 AC 17 ms
8,036 KB
testcase_04 AC 18 ms
8,060 KB
testcase_05 AC 17 ms
8,096 KB
testcase_06 AC 17 ms
8,108 KB
testcase_07 AC 16 ms
8,036 KB
testcase_08 AC 16 ms
8,220 KB
testcase_09 AC 16 ms
8,060 KB
testcase_10 AC 17 ms
8,064 KB
testcase_11 AC 16 ms
8,040 KB
testcase_12 AC 16 ms
8,116 KB
testcase_13 AC 2,541 ms
58,196 KB
testcase_14 AC 2,539 ms
58,256 KB
testcase_15 AC 47 ms
9,724 KB
testcase_16 AC 142 ms
11,632 KB
testcase_17 AC 97 ms
10,044 KB
testcase_18 AC 79 ms
10,932 KB
testcase_19 AC 65 ms
8,644 KB
testcase_20 AC 1,830 ms
41,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)
n,q=map(int,input().split())
c=list(map(int,input().split()))

def init(n):
    global seg
    global N
    N=1
    while N < n:
        N <<= 1
    seg=[0]*(N + N-1)
def query(l, r):
    return _query(l, r, 0, 0, N)
def _query(l, r, i, L, R):
    if l <= L and R <= r:
        return seg[i]
    if R<=l or r <= L:
        return 0
    m=(L+R)//2
    v1 = _query(l, r, i*2+1,L, m)
    v2 = _query(l, r, i*2+2, m, R)
    return v1 ^ v2

def update(i,x):
    j=i + N-1
    seg[j]^=x
    while j > 0:
        j = (j - 1) // 2
        seg[j] = seg[j*2+1]^seg[j*2+2]
    

def rec(v, p, vs, g, l , r):
    l[v]=len(vs)
    vs.append(v)
    for nv in g[v]:
        if nv == p:
            continue
        rec(nv, v, vs, g, l, r)
    r[v]=len(vs)

g=  [[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(lambda x: int(x)-1, input().split())
    g[a].append(b)
    g[b].append(a)

vs = []
l = [0]*n
r = [0]*n
rec(0, -1, vs, g, l, r)
init(len(vs))
for i in range(len(vs)):
    update(i, c[vs[i]])

for _ in range(q):
    t, x, y = map(int, input().split())
    x-=1
    if t==1:
        update(l[x], y)
    else:
        print(query(l[x], r[x]))
0