Submission #448277

# Submission time Handle Problem Language Result Execution time Memory
448277 2021-07-29T13:14:01 Z mychecksedad XORanges (eJOI19_xoranges) C++17
0 / 100
43 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e3+10;

int n, q, arr[N], qt, t1[5*N], t2[5*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;
//         }
//     }
//     return 0;
// }
void init(int l, int r, int k){
    if(l==r){
        t1[k]=t2[k]=0;
        if(l&1) t1[k]=arr[l];
        else t2[k]=arr[l];
        return;
    }
    int mid = (l+r)/2;
    init(l, mid, 2*k);
    init(mid+1, r, 2*k+1);
    t1[k] = t1[2*k]^t1[2*k+1];
    t2[k] = t2[2*k]^t2[2*k+1];
}
void update(int l, int r, int p, int val, int k){
    if(l > p || r < p) return;
    if(l == r){
        if(l&1) t1[k] = val;
        else t2[k] = val;
        return;
    }int mid = (l+r)/2;
    update(l, mid, p, val, 2*k);
    update(mid+1, r, p, val, 2*k+1);
    t1[k] = t1[2*k]^t1[2*k+1];
    t2[k] = t2[2*k]^t2[2*k+1];
}
int ans(int l, int r, int ql, int qr, int k){
    if(l > qr || r < ql) return 0;
    if(l <= ql && r <= qr){
        return (ql & 1 ? t1[k] : t2[k]);
    }
    int mid = (l+r)/2;
    return ans(l, mid, ql, qr, 2*k) ^ ans(mid+1, r, ql, qr, 2*k+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(1, n, 1);
    while(q--){
        int l, r;
        cin >> qt >> l >> r;
        if(qt == 1){
            update(1, n, l, r, 1);
        }
        else
            cout << ans(1, n, l, r, 1) << '\n';
        
    }




    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -