Submission #448303

# Submission time Handle Problem Language Result Execution time Memory
448303 2021-07-29T14:02:16 Z mychecksedad XORanges (eJOI19_xoranges) C++17
100 / 100
138 ms 6936 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, po)-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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 6416 KB Output is correct
2 Correct 126 ms 6868 KB Output is correct
3 Correct 130 ms 6900 KB Output is correct
4 Correct 116 ms 6852 KB Output is correct
5 Correct 118 ms 6936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
15 Correct 126 ms 6416 KB Output is correct
16 Correct 126 ms 6868 KB Output is correct
17 Correct 130 ms 6900 KB Output is correct
18 Correct 116 ms 6852 KB Output is correct
19 Correct 118 ms 6936 KB Output is correct
20 Correct 138 ms 6336 KB Output is correct
21 Correct 122 ms 6364 KB Output is correct
22 Correct 123 ms 6344 KB Output is correct
23 Correct 118 ms 6824 KB Output is correct
24 Correct 119 ms 6808 KB Output is correct