CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Xor sum
Sender:louaha1
Submission time:2024-09-23 16:29:53 +0300
Language:Python3 (CPython3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.78 sdetails

Code

def process_queries(n, q, arr, queries):
    # Step 1: Compute the prefix_xor array
    prefix_xor = [0] * (n + 1)
    
    for i in range(1, n + 1):
        prefix_xor[i] = prefix_xor[i - 1] ^ arr[i - 1]
    
    # Step 2: Answer each query
    results = []
    for a, b in queries:
        result = prefix_xor[b] ^ prefix_xor[a - 1]
        results.append(result)
    
    return results

# Input reading
n, q = map(int, input().split())
arr = list(map(int, input().split()))
queries = [tuple(map(int, input().split())) for _ in range(q)]

# Process and output the results
results = process_queries(n, q, arr, queries)
for result in results:
    print(result)

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