| Task: | Xor sum |
| Sender: | aalto26dm_045 |
| Submission time: | 2026-09-21 16:36:08 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.34 s | details |
Code
import sys
input = sys.stdin.read().split()
n = int(input[0])
q = int(input[1])
#def xor = (lambda x,y = x^y)
def build() :
tree = [float('inf')] * (2*n)
for i in range(n):
tree[n+i] = int(input[2+i])
for i in range(n-1,0,-1):
tree[i] = tree[2*i] ^ tree[(2*i)+1]
return tree
def query(tree, start, end):
l = start +n
r = end +n
res = 0
while l <= r:
if l%2 ==1 :
res ^= tree[l]
l = l+1
if r%2 ==0:
res ^= tree[r]
r = r-1
l = l//2
r = r//2
return res
tree = build()
i = n+2
for _ in range(q):
print(query(tree, int(input[i])-1, int(input[i+1])-1))
i = i+2Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 8 36 7 6 4 6 2 9 4 8 1 1 1 2 1 3 ... |
| correct output |
|---|
| 7 1 5 3 1 ... |
| user output |
|---|
| 7 1 5 3 1 ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 921726510 307633388 992247073 ... |
| correct output |
|---|
| 834756431 130379787 403037296 308618218 784778243 ... |
| user output |
|---|
| 834756431 130379787 403037296 308618218 784778243 ... |
