Submission #448292

# Submission time Handle Problem Language Result Execution time Memory
448292 2021-07-29T13:35:19 Z mychecksedad XORanges (eJOI19_xoranges) C++17
0 / 100
149 ms 4848 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 2e5+10;

int n, q, arr[N], qt, t1[4*N], t2[4*N], len;

void init(){
    len = pow(2, int(log2(n)))-1;
    for(int i = 0; i <= len*2+10; i++) t1[i] = t2[i] = 0;
    for(int i = 1; i <= n; i++){
        if(i&1) t1[i+len] = arr[i];
        else t2[i+len] = arr[i];
    }
    for(int i = len; i > 0; i--){
        t1[i] = (t1[2*i] ^ t1[2*i+1]);
        t2[i] = (t2[2*i] ^ t2[2*i+1]);
    } 
}

void update(int p, int val){
    if(p&1){
        arr[p] = val;
        for(t1[p += len] = val; p > 1; p >>= 1) t1[p/2] = t1[p]^t1[p^1];
    }else{
        arr[p] = val;
        for(t2[p += len] = val; p > 1; p >>= 1) t1[p/2] = t2[p]^t2[p^1];
    }
}
int ans(int l, int r){
    int x = 0;
    if(l & 1){
        r++;
        for(l += len, r += len; l < r; l >>= 1, r >>= 1){
            if(l & 1) x ^= t1[l++];
            if(r & 1) x ^= t1[--r];
        }
        return x;
    }else{
        r++;
        for(l += len, r += len; l < r; l >>= 1, r >>= 1){
            if(l & 1) x ^= t2[l++];
            if(r & 1) x ^= t2[--r];
        }
        return x;
    }
    return x;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n >> q;
    for(int i = 1; i <= n; i++) cin >> arr[i];
    init();
    while(q--){
        int l, r;
        cin >> qt >> l >> r;
        if(qt == 1){
            update(l, r);
        }
        else
            cout << (((r - l + 1)&1) ? ans(l, r) : 0) << '\n';
        
    }




    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 4848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -