답안 #1006373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006373 2024-06-23T21:47:41 Z JoksimKaktus XORanges (eJOI19_xoranges) C++17
100 / 100
90 ms 11968 KB
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
vector <int> seg1(200000*3);
vector <int> seg2(200000*3);
vector <int> v(200000);
 
void build(int l,int r,int u){
    if(l == r){
        if(l % 2 == 1){
            return;
        }
        seg1[u] = v[l];
        return;
    }
    build(l,(l+r)/2,u*2);
    build((l+r)/2+1,r,u*2+1);
    seg1[u] = seg1[u*2]^seg1[u*2+1];
}
 
void update(int l,int r,int u,int v,int k){
    if(l == r && l == v){
        seg1[u] = k;
        return;
    }
    if(v < l || v > r)return;
    update(l,(l+r)/2,u*2,v,k);
    update((l+r)/2+1,r,u*2+1,v,k);
    seg1[u] = seg1[u*2]^seg1[u*2+1];
}
 
int find(int l,int r,int u,int a,int b,int res){
    if(a <= l && b >= r){
        return seg1[u]^res;
    }
    if(l > b || r < a){
        return res;
    }
    res = find(l,(l+r)/2,u*2,a,b,res);
    res = find((l+r)/2+1,r,u*2+1,a,b,res);
    return res;
}
 
void build2(int l,int r,int u){
    if(l == r){
        if(l % 2 == 0){
            return;
        }
        seg2[u] = v[l];
        return;
    }
    build2(l,(l+r)/2,u*2);
    build2((l+r)/2+1,r,u*2+1);
    seg2[u] = seg2[u*2]^seg2[u*2+1];
}
 
void update2(int l,int r,int u,int v,int k){
    if(l == r && l == v){
        seg2[u] = k;
        return;
    }
    if(v < l || v > r)return;
    update2(l,(l+r)/2,u*2,v,k);
    update2((l+r)/2+1,r,u*2+1,v,k);
    seg2[u] = seg2[u*2]^seg2[u*2+1];
}
 
int find2(int l,int r,int u,int a,int b,int res){
    if(a <= l && b >= r){
        return seg2[u]^res;
    }
    if(l > b || r < a){
        return res;
    }
    res = find2(l,(l+r)/2,u*2,a,b,res);
    res = find2((l+r)/2+1,r,u*2+1,a,b,res);
    return res;
}
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,q;
    cin >> n >> q;
    for(int i = 0;i < n;i++){
        cin >> v[i];
    }
    build(0,n-1,1);
    build2(0,n-1,1);
    while(q--){
        /*
        for(int i = 0;i < 20;i++){
            cout << seg1[i] << " ";
        }
        cout << "\n";
        for(int i = 0;i < 20;i++){
            cout << seg2[i] << " ";
        }
         */
        //cout << "\n";
        int x,l,r;
        cin >> x >> l >> r;
        if(x == 1){
            l--;
            if(l % 2 == 0){
                update(0,n-1,1,l,r);
            }else{
                update2(0,n-1,1,l,r);
            }
        }else{
            l--;
            r--;
            if((r-l) % 2 == 1){
                cout << "0\n";
            }else{
                if(l%2 == 0){
                    cout << find(0,n-1,1,l,r,0) << "\n";
                }else{
                    cout << find2(0,n-1,1,l,r,0) << "\n";
                }
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5768 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5952 KB Output is correct
5 Correct 2 ms 5960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5768 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5952 KB Output is correct
10 Correct 2 ms 5960 KB Output is correct
11 Correct 4 ms 5980 KB Output is correct
12 Correct 5 ms 6056 KB Output is correct
13 Correct 4 ms 5980 KB Output is correct
14 Correct 4 ms 5980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 11968 KB Output is correct
2 Correct 75 ms 11932 KB Output is correct
3 Correct 80 ms 11732 KB Output is correct
4 Correct 69 ms 11604 KB Output is correct
5 Correct 90 ms 11604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5768 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5952 KB Output is correct
10 Correct 2 ms 5960 KB Output is correct
11 Correct 4 ms 5980 KB Output is correct
12 Correct 5 ms 6056 KB Output is correct
13 Correct 4 ms 5980 KB Output is correct
14 Correct 4 ms 5980 KB Output is correct
15 Correct 78 ms 11968 KB Output is correct
16 Correct 75 ms 11932 KB Output is correct
17 Correct 80 ms 11732 KB Output is correct
18 Correct 69 ms 11604 KB Output is correct
19 Correct 90 ms 11604 KB Output is correct
20 Correct 86 ms 11584 KB Output is correct
21 Correct 87 ms 11604 KB Output is correct
22 Correct 82 ms 11640 KB Output is correct
23 Correct 72 ms 11392 KB Output is correct
24 Correct 71 ms 11624 KB Output is correct