| Task: | Xor sum |
| Sender: | banghalq |
| Submission time: | 2025-09-22 16:20:23 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.82 s | details |
Code
n,q = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
square_n = int(round(n**(1/2), 0))
sqrt_array_size = square_n
if square_n * square_n < n:
sqrt_array_size += 1
sqrt_array = [0 for _ in range(sqrt_array_size)]
#preprocess
for i in range(sqrt_array_size):
reduces_array = array[i*square_n:(i+1)*square_n]
for elt in reduces_array:
sqrt_array[i] = sqrt_array[i] ^ elt
def query(a, b):
res = 0
while (a < b) and (a % square_n != 0) and (a != 0): #before block
res = array[a] ^ res
a += 1
while a + square_n - 1 <= b: #overlapped blocks
res = sqrt_array[a//square_n] ^ res
a += square_n
while a <= b: #after block
res = array[a] ^ res
a += 1
return res
solution = []
for _ in range(q):
a, b = [int(x) for x in input().split()]
solution.append(query(a-1,b-1))
for elt in solution:
print(elt)
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 |
