Submission #448302

# Submission time Handle Problem Language Result Execution time Memory
448302 2021-07-29T14:00:52 Z mychecksedad XORanges (eJOI19_xoranges) C++17
0 / 100
129 ms 5764 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(){
    int po;
    if(pow(2, int(log2(n))) == n) po = int(log2(n));
    else po = int(log2(n)) - 1;
    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){
    arr[p] = val;
    if(p&1)
        for(t1[p += len] = val; p > 1; p >>= 1) t1[p/2] = t1[p]^t1[p^1];
    else
        for(t2[p += len] = val; p > 1; p >>= 1) t2[p/2] = t2[p]^t2[p^1];
}
int ans(int l, int r){
    int x = 0;
    r++;
    if(l & 1){
        for(l += len, r += len; l < r; l >>= 1, r >>= 1){
            if(l & 1) x ^= t1[l++];
            if(r & 1) x ^= t1[--r];
        }
    }else{
        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;
}

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;
}

Compilation message

xoranges.cpp: In function 'void init()':
xoranges.cpp:9:9: warning: variable 'po' set but not used [-Wunused-but-set-variable]
    9 |     int po;
      |         ^~
# 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 129 ms 5764 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 -