| Task: | Xor sum |
| Sender: | kookinnam |
| Submission time: | 2025-09-22 16:25:58 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.04 s | details |
| #2 | WRONG ANSWER | 0.53 s | details |
Code
class SegmentTree:
def __init__(self,n, data):
self.n = n
self.size = 1
while self.size < self.n:
self.size <<= 1
self.tree = [0] * (2 * self.size)
# Build tree
for i in range(self.n):
self.tree[self.size + i] = data[i]
for i in range(self.size - 1, 0, -1):
self.tree[i] = self.tree[2*i] ^ self.tree[2*i + 1]
def update(self, idx, val):
idx += self.size
self.tree[idx] = val
idx //= 2
while idx > 0:
self.tree[idx] = self.tree[2*idx] ^ self.tree[2*idx + 1]
idx //= 2
def query(self, left, right):
left += self.size
right += self.size
res = 0
while left <= right:
if left % 2 == 1:
res += self.tree[left]
left += 1
if right % 2 == 0:
res += self.tree[right]
right -= 1
left //= 2
right //= 2
return res
def rangeQuery(n, q, arr, commands):
result = []
tree = SegmentTree(n, arr)
for command in commands:
result.append(tree.query(command[0] - 1, command[1] - 1))
return result
def main():
n, q = map(int, input().split())
arr = list(map(int, input().split()))
commands = [list(map(int, input().split())) for _ in range(q)]
result = rangeQuery(n, q, arr, commands)
print(*result, sep='\n')
if __name__ == "__main__":
main()Test details
Test 1
Verdict: WRONG ANSWER
| 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 5 ... |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 921726510 307633388 992247073 ... |
| correct output |
|---|
| 834756431 130379787 403037296 308618218 784778243 ... |
| user output |
|---|
| 8256685189 12017300475 8993450744 6472685682 10611417179 ... Truncated |
