답안 #1021239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021239 2024-07-12T16:13:12 Z mar XORanges (eJOI19_xoranges) C++14
0 / 100
454 ms 8876 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int seg1[600009];
int seg2[600009];
int v[600009];
 
void build(int id,int l,int r){
    if(l == r){
        if(l % 2 == 1){
            return;
        }
        seg1[id] = v[l];
        return;
    }
    int mid = (l+r)/2;
    build(id*2,l,mid);
    build(id*2+1,mid+1,r);
    seg1[id] = seg1[id*2]^seg1[id*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;
    int mid = (l+r)/2;
    update(l,mid,u*2,v,k);
    update(mid+1,r,u*2+1,v,k);
    seg1[u] = seg1[u*2]^seg1[u*2+1];
}
 
int query(int id,int l,int r,int a,int b,int res){
    if(a <= l && b >= r){
        return seg1[id]^res;
    }
    if(l > b || r < a){
        return res;
    }
    int mid = (l+r)/2;
    res = query(id*2,l,mid,a,b,res);
    res = query(id*2+1,mid+1,r,a,b,res);
    return res;
}
 
void build2(int id,int l,int r){
    if(l == r){
        if(l % 2 == 0){
            return;
        }
        seg2[id] = v[l];
        return;
    }
    int mid = (l+r)/2;
    build(id*2,l,mid);
    build(id*2+1,mid+1,r);
    seg2[id] = seg2[id*2]^seg2[id*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;
    int mid = (l+r)/2;
    update2(l,mid,u*2,v,k);
    update2(mid+1,r,u*2+1,v,k);
    seg2[u] = seg2[u*2]^seg2[u*2+1];
}
 
int query2(int id,int l,int r,int a,int b,int res){
    if(a <= l && b >= r){
        return seg2[id]^res;
    }
    if(l > b || r < a){
        return res;
    }
    int mid = (l+r)/2;
    res = query2(id*2,l,mid,a,b,res);
    res = query2(id*2+1,mid+1,r,a,b,res);
    return res;
}
 
int main() {
    int n,q;
    cin >> n >> q;
    for(int i = 0;i < n;i++){
        cin >> v[i];
    }
    build(1,0,n-1);
    build2(1,0,n-1);
    while(q--){
        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<<query(1,0,n-1,l,r,0)<<endl;
                }else{
                    cout<<query2(0,n-1,1,l,r,0)<<endl;
                }
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 454 ms 8876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -