Submission #1298734

#TimeUsernameProblemLanguageResultExecution timeMemory
1298734miyamae_nonoaXORanges (eJOI19_xoranges)C++20
55 / 100
1095 ms6176 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nmax = 2e5 + 5;
ll a[nmax], st[4*nmax];
int n, q;
void build(int id, int start, int end) {
    if (start == end) {
        st[id] = a[start];
    } else {
        int mid = (start + end) / 2;
        build(2*id, start, mid);
        build(2*id+1, mid+1, end);
        st[id] = st[2*id] ^ st[2*id+1];
    }
}
void update(int id, int start, int end, int idx, int val) {
    if (start == end) {
        st[id] = val;
        a[idx] = val;
    } else {
        int mid = (start + end) / 2;
        if (idx <= mid) update(2*id, start, mid, idx, val);
        else update(2*id+1, mid+1, end, idx, val);
        st[id] = st[2*id] ^ st[2*id+1];
    }
}
ll query(int id, int start, int end, int l, int r) {
    if (r < start || end < l) return 0;
    if (l <= start && end <= r) return st[id]; 
    int mid = (start + end) / 2;
    ll p1 = query(2*id, start, mid, l, r);
    ll p2 = query(2*id+1, mid+1, end, l, r);
    return p1 ^ p2;
}
int main() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> a[i];
    build(1, 1, n);
    while (q--) {
        int type, x, y;
        cin >> type >> x >> y;
        if (type == 1) update(1, 1, n, x, y);
        else {
            int l = x, r = y;
            int ans = 0;
            for (int i = l; i <= r; i++) {
                ll cnt = (i-l+1) * (r-i+1);
                if (cnt % 2 == 1) ans ^= a[i];
            }
            cout << ans << "\n";
        }
    }
}
#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...