Submission #448256

# Submission time Handle Problem Language Result Execution time Memory
448256 2021-07-29T12:40:53 Z mychecksedad XORanges (eJOI19_xoranges) C++17
0 / 100
124 ms 9668 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[3*N], t2[3*N], len;

void init(){
    len = pow(2, int(log2(n)))-1;
    for(int i = 0; i < len*2+2; 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){
        int pp=p;
        for(p += len; p > 0; p >>= 1) t1[p] ^= arr[pp];
        p=pp;
        arr[p] = val;
        for(p += len; p > 0; p >>= 1) t1[p] ^= val;
    }else{
        int pp=p;
        for(p += len; p > 0; p >>= 1) t2[p] ^= arr[pp];
        p=pp;
        arr[p] = val;
        for(p += len; p > 0; p >>= 1) t2[p] ^= val;
    }
}
int ans(int l, int r){
    int a = r - l + 1;
    if(a & 1){
        if(l & 1){
            r++;
            int x = 0;
            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{
            int x = 0;
            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;
        }
    }else return 0;
    return 1;
}

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 << ans(l, r) << '\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 324 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 124 ms 9668 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 -