Submission details
Task:Xor sum
Sender:aalto26dm_025
Submission time:2026-09-21 16:30:43 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.60 sdetails

Code

#include <iostream>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

int xor_in_range(int a, int b, vector<int> & tree)
{
    int n = tree.size() / 2;
    a += n; b += n;
    int s = 0;
    while (a <= b)
    {
        if (a%2 == 1) s = tree[a++] ^ s;
        if (b%2 == 0) s = tree[b--] ^ s;
        a /= 2; b /= 2;
    }
    return s;
}

void add(int k, int x, vector<int> & tree)
{
    int n = tree.size() / 2;
    k += n;
    tree[k] = x;
    for (k /= 2; k >= 1; k /= 2)
    {
        if(tree[2*k+1] != -1) tree[k] = tree[2*k] ^ tree[2*k+1];
        else tree[k] = tree[2*k];
    }
}


int main()
{
    int n_values, n_queries;
    cin >> n_values >> n_queries;

    int base_array_size = pow(2, ceil(log2(n_values)));
    int full_array_size = 2 * base_array_size;
    vector<int> segmented_tree(full_array_size, -1);

    for(int i = 0; i < n_values; ++i)
    {
        int temp;
        cin >> temp;
        add(i, temp, segmented_tree);
    }

    for(int i = 0; i < n_queries; ++i)
    {
        int op1, op2;
        cin >> op1 >> op2;

        cout << xor_in_range(op1 - 1, op2 - 1, segmented_tree) << endl;
    }
 


}

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