Submission #1197750

#TimeUsernameProblemLanguageResultExecution timeMemory
1197750SzymonKrzywdaXORanges (eJOI19_xoranges)C++20
100 / 100
69 ms4688 KiB
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <queue>
#include <unordered_set>
#include <set>

using namespace std;


vector<int> ile(int n){
    vector<int> w(n, 0);

    for (int i = 1; i <= n; i++){
        for (int j = 0; j + i - 1 < n; j++){
            for (int k = j; k < j + i; k++) w[k]++;
        }
    }

    return w;
}


const int base = 1 << 18;

int tree[base * 2][2];



void update(int idx, int val){
    int p = idx % 2;
    idx += base;

    tree[idx][p] = val;
    idx /= 2;

    while (idx){
        tree[idx][p] = tree[idx * 2][p] ^ tree[idx * 2 + 1][p];
        idx /= 2;
    }
}

int query(int l, int r){
    int p = l % 2;
    l += base - 1;
    r += base + 1;

    int wynik = 0;

    while (l / 2 != r / 2){
        if (l % 2 == 0) wynik ^= tree[l + 1][p];
        if (r % 2 == 1) wynik ^= tree[r - 1][p];

        l /= 2;
        r /= 2;
    }

    return wynik;
}



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    int n, q, a, b, c;
    cin >> n >> q;

    for (int i = 1; i <= n; i++){
        cin >> a;
        update(i, a); 
    }


    for (int i = 0; i < q; i++){
        cin >> a >> b >> c;

        if (a == 2){
            if ((c - b + 1) % 2 == 0) cout << 0 << '\n';
            else cout << query(b, c) << '\n';
        }
        else update(b, c);
    }
    

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...