結果
問題 | No.1641 Tree Xor Query |
ユーザー | momoyuu |
提出日時 | 2022-08-03 02:47:16 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,994 bytes |
コンパイル時間 | 372 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 583,700 KB |
最終ジャッジ日時 | 2024-07-23 20:51:56 |
合計ジャッジ時間 | 7,849 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,244 KB |
testcase_01 | AC | 38 ms
53,700 KB |
testcase_02 | AC | 37 ms
53,120 KB |
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 | AC | 38 ms
53,724 KB |
testcase_13 | MLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
ソースコード
def main(): import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline 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)] 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) import math 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] q = math.floor(math.sqrt(Q)) nowq = 0 while True: for i in range(N): l[i] = 0 dfs(0) p = 1 txy = [] for i in range(q): nq = q * nowq + i if nq >= Q: p = 0 break txy.append(list(map(int,input().split()))) if txy[i][0] == 1: continue s = sum[txy[i][1]-1] for j in range(i): # nnq = q * nowq + j # nt,nx,ny = txy[j] if txy[j][0] == 2: continue nx -= 1 if d[txy[i][1]-1][0] <= d[txy[j][1]-1][0] <= d[txy[i][1]-1][1]: s ^= txy[j][2] print(s) if not p: break for i in range(q): if txy[i][0] == 2: continue C[txy[i][1]-1] ^= txy[i][2] nowq += 1 if __name__ == '__main__': main()