답안 #448289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448289 2021-07-29T13:28:51 Z mychecksedad XORanges (eJOI19_xoranges) C++17
100 / 100
204 ms 11184 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+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(ql <= l && 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 << (((r - l + 1)&1) ? ans(1, n, l, r, 1) : 0) << '\n';
        
    }




    return 0;
}
# 결과 실행 시간 메모리 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 320 KB Output is correct
# 결과 실행 시간 메모리 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 332 KB Output is correct
# 결과 실행 시간 메모리 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 320 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 332 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 7468 KB Output is correct
2 Correct 172 ms 11156 KB Output is correct
3 Correct 177 ms 11184 KB Output is correct
4 Correct 148 ms 10820 KB Output is correct
5 Correct 144 ms 10892 KB Output is correct
# 결과 실행 시간 메모리 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 320 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 332 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
15 Correct 204 ms 7468 KB Output is correct
16 Correct 172 ms 11156 KB Output is correct
17 Correct 177 ms 11184 KB Output is correct
18 Correct 148 ms 10820 KB Output is correct
19 Correct 144 ms 10892 KB Output is correct
20 Correct 175 ms 11076 KB Output is correct
21 Correct 180 ms 10956 KB Output is correct
22 Correct 170 ms 10852 KB Output is correct
23 Correct 146 ms 10864 KB Output is correct
24 Correct 144 ms 10840 KB Output is correct