답안 #912504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912504 2024-01-19T14:45:49 Z andro XORanges (eJOI19_xoranges) C++14
100 / 100
108 ms 20048 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;
const int N=2e5+50;
const int inf=1e18;
const int mod=1e9+7;
int a[N];
int n;
int q;
int A[N];
struct segtree{
    int t[4*N]={0};
    void build(int v,int tl,int tr){
        if(tl==tr)t[v]=A[tl];
        else {
            int tm=(tl+tr)/2;
            build(v*2,tl,tm);
            build(v*2+1,tm+1,tr);
            t[v]=(t[v*2]^t[v*2+1]);
        }
    }
    int query(int v,int tl,int tr,int l,int r){
        if(tr<l||tl>r)return 0;
        if(l<=tl&&tr<=r)return t[v];
        int tm=(tl+tr)/2;
        return (query(v*2,tl,tm,l,r)^query(v*2+1,tm+1,tr,l,r));
    }
    void update(int v,int tl,int tr,int index,int value){
        if(tl==tr){
            t[v]=value;
        }
        else {
            int tm=(tl+tr)/2;
            if(index<=tm){
                update(v*2,tl,tm,index,value);
            }
            else {
                update(v*2+1,tm+1,tr,index,value);
            }
            t[v]=(t[v*2]^t[v*2+1]);
        }
    }
};
segtree seg[2];
/*
int brute(int l,int r){
    int ans=0;
            for(int i=l;i<=r;i++){
                for(int j=i;j<=r;j++){
                    ans^=seg.query(1,1,n,i,j);
                }
            }
            return ans;
}
*/
int solve(int l,int r,int o){
    if((r-l+1)%2==0)return 0;
    return seg[o].query(1,1,n,l,r);
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        if(i%2==0)A[i]=a[i];
        else A[i]=0;
    }
    seg[0].build(1,1,n);
    for(int i=1;i<=n;i++){
        if(i%2==0)A[i]=0;
        else A[i]=a[i];
    }
    seg[1].build(1,1,n);
    while(q--){
        int o;
        cin>>o;
        if(o==1){
            int i,x;
            cin>>i>>x;
            seg[i%2].update(1,1,n,i,x);
        }
        else {
            int l,r;
            cin>>l>>r;
            cout<<solve(l,r,l%2);
            cout<<"\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4572 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4556 KB Output is correct
6 Correct 2 ms 4572 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 4 ms 6744 KB Output is correct
12 Correct 4 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 20048 KB Output is correct
2 Correct 99 ms 19920 KB Output is correct
3 Correct 101 ms 19932 KB Output is correct
4 Correct 86 ms 19536 KB Output is correct
5 Correct 94 ms 19728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4556 KB Output is correct
6 Correct 2 ms 4572 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 4 ms 6744 KB Output is correct
12 Correct 4 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6860 KB Output is correct
15 Correct 98 ms 20048 KB Output is correct
16 Correct 99 ms 19920 KB Output is correct
17 Correct 101 ms 19932 KB Output is correct
18 Correct 86 ms 19536 KB Output is correct
19 Correct 94 ms 19728 KB Output is correct
20 Correct 95 ms 19800 KB Output is correct
21 Correct 92 ms 19824 KB Output is correct
22 Correct 103 ms 19568 KB Output is correct
23 Correct 108 ms 19536 KB Output is correct
24 Correct 87 ms 19728 KB Output is correct