Submission details
Task:Xor sum
Sender:aalto26dm_024
Submission time:2026-09-21 16:28:15 +0300
Language:Python3 (PyPy3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.71 sdetails

Code

import math

def main():
    n, q = [int(x) for x in input().split()]
    values = [int(x) for x in input().split()]

    N = 1
    while N < n:
        N *= 2

    tree = [0] * N * 2

    for i in range(n):
        tree[N + i] = values[i]
    for i in range(N - 1, 0, -1):
        tree[i] = tree[i * 2] ^ tree[i * 2 + 1]

    def query(a, b):
        a += N
        b += N
        s = 0

        while a <= b:
            if a % 2 == 1:
                s = s ^ tree[a]
                a += 1
            if b % 2 == 0:
                s = s ^ tree[b]
                b -= 1
            a //= 2
            b //= 2
        return s

    for _ in range(q):
        action = [int(x) for x in input().split()]

        print(query(action[0] - 1, action[1] - 1))

main()

Test 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
...