結果
問題 | No.1641 Tree Xor Query |
ユーザー | momoyuu |
提出日時 | 2022-08-03 02:34:45 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,708 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 82,484 KB |
実行使用メモリ | 529,984 KB |
最終ジャッジ日時 | 2024-07-23 20:38:08 |
合計ジャッジ時間 | 7,667 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,868 KB |
testcase_01 | AC | 39 ms
52,880 KB |
testcase_02 | AC | 39 ms
53,340 KB |
testcase_03 | AC | 40 ms
53,700 KB |
testcase_04 | AC | 51 ms
63,660 KB |
testcase_05 | AC | 50 ms
63,064 KB |
testcase_06 | AC | 51 ms
61,172 KB |
testcase_07 | AC | 48 ms
61,336 KB |
testcase_08 | AC | 39 ms
53,124 KB |
testcase_09 | AC | 41 ms
53,528 KB |
testcase_10 | AC | 42 ms
54,400 KB |
testcase_11 | AC | 40 ms
54,364 KB |
testcase_12 | AC | 42 ms
54,008 KB |
testcase_13 | MLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
ソースコード
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) 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 = 1 txy = [] for i in range(q): nq = q * nowq + i if nq >= Q: p = 0 break txy.append(list(map(int,input().split()))) t,x,y = txy[i] if t == 1: continue x -= 1 s = sum[x] for j in range(i): nnq = q * nowq + j nt,nx,ny = txy[j] 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[i] if t == 2: continue x -= 1 C[x] ^= y nowq += 1