Submission #1360294

#TimeUsernameProblemLanguageResultExecution timeMemory
1360294aleksandreXORanges (eJOI19_xoranges)C++20
100 / 100
81 ms11408 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define vii vector <int>
#define endl '\n'
#define lb lower_bound
#define ub upper_bound
const int inf = 1e18;
const int N = 2e5+5;
int a[N];
int t[2][4*N]; 
void update(int x, int node, int l, int r, int pos, int val) {
    if (l == r) {
        t[x][node] = val;
        return;
    }
    int mid = (l+r)/2;
    if (pos <= mid) update(x, node*2, l, mid, pos, val);
    else update(x, node*2+1, mid+1, r, pos, val);
    t[x][node] = (t[x][node*2] ^ t[x][node*2+1]);
}

int getans(int x, int node, int l, int r, int L, int R) {
    if (r < L || R < l) return 0;
    if (L <= l && r <= R) return t[x][node];
    int mid = (l+r)/2;
    return (getans(x, node*2, l, mid, L, R) ^ getans(x, node*2+1, mid+1, r, L, R));
}

inline void test_case() {
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        update(i%2, 1, 1, n, i, a[i]);
    }
    while (q--) {
        int type, i, j;
        cin >> type >> i >> j;
        if (type == 1) {
            a[i] = j;
            update(i%2, 1, 1, n, i, j);
        } else {
            if ((j-i+1) % 2 == 0) {
                cout << 0 << endl;
            } else {
                cout << getans(i%2, 1, 1, n, i, j) << endl;
            }
        }
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) test_case();
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...