CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Xor sum
Sender:esya_rae
Submission time:2024-09-23 16:23:30 +0300
Language:Python3 (PyPy3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.85 sdetails

Code

import math
def build_tree(i):
global x, tree, k, n
if i >= k + n:
return 0
if i >= k:
tree[i] = x[i - k]
return tree[i]
tree[i] = build_tree(2 * i) ^ build_tree(2 * i + 1)
return tree[i]
def answer(a, b):
global tree, k
res = 0
a += k
b += k
while a <= b:
if a % 2 == 1:
res = res ^ tree[a]
a += 1
if b % 2 == 0:
res = res ^ tree[b]
b -= 1
a //= 2
b //= 2
return res
n, q = map(int, input().split())
x = list(map(int, input().split()))
k = 2 ** math.ceil(math.log(n, 2))
tree = [0] * (2 * k)
build_tree(1)
for i in range(q):
j, u = map(int, input().split())
print(answer(j - 1, u - 1))

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