結果
問題 | No.1641 Tree Xor Query |
ユーザー | momoyuu |
提出日時 | 2022-08-03 02:30:15 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,659 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 204,180 KB |
最終ジャッジ日時 | 2024-07-23 20:34:11 |
合計ジャッジ時間 | 3,925 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
ソースコード
N,Q = map(int,input().split()) C = list(map(int,input().split())) def f(n): return int(n) - 1 ab = [list(map(f,input().split())) for _ in range(N-1)] txy = [list(map(int,input().split())) for _ in range(Q)] e = [[] for _ in range(N)] for i in range(N-1): a,b = ab[i] e[a].append(b) e[b].append(a) sum = [0 for _ in range(N)] d = [[0,0] for _ in range(N)] import sys sys.setrecursionlimit(10**6) l = [0 for _ in range(N)] def euler(n,k): d[n][0] = k l[n] = 1 now = k for i in e[n]: if l[i] == 1: continue qqq = euler(i,now+1) now = qqq d[n][1] = now + 1 return (now + 1) euler(0,0) del e import math def calcsum(): l = [0 for _ in range(N)] def dfs(n): l[n] = 1 sum[n] = C[n] for i in e[n]: if l[i]: continue s = dfs(i) sum[n] ^= s return sum[n] dfs(0) calcsum() q = math.floor(math.sqrt(Q)) nowq = 0 while True: calcsum() p = True for i in range(q): nq = q * nowq + i if nq >= Q: p = False break t,x,y = txy[nq] if t == 1: continue x -= 1 s = sum[x] for j in range(i): nnq = q * nowq + j nt,nx,ny = txy[nnq] if nt == 2: continue nx -= 1 if d[x][0] <= d[nx][0] <= d[x][1]: s ^= ny print(s) if not p: break for i in range(q): nq = q * nowq + i t,x,y = txy[nq] if t == 2: continue x -= 1 C[x] ^= y nowq += 1