Submission #288240

# Submission time Handle Problem Language Result Execution time Memory
288240 2020-09-01T10:45:17 Z Benmath XORanges (eJOI19_xoranges) C++14
100 / 100
998 ms 10104 KB
#include<bits/stdc++.h>
using namespace std;
int arr[200000];
int tree1[800000];
int tree2[800000];
int b[200000];
int c[200000];
void build1(int node,int start,int end){
 if(start==end){
        tree1[node]=b[start];
    }else{
        int mid=(start+end)/2;
        build1(2*node,start,mid);
        build1(2*node+1,mid+1,end);
        tree1[node]=tree1[2*node] ^ tree1[2*node+1];
    }

}
void build2(int node,int start,int end){
    if(start==end){
        tree2[node]=c[start];
    }else{
        int mid=(start+end)/2;
        build2(2*node,start,mid);
        build2(2*node+1,mid+1,end);
        tree2[node]=tree2[2*node] ^ tree2[2*node+1];
    }

}
void update1(int node,int start,int end,int index,int val){
    if(start==end){
        tree1[node]=val;
        b[index]=val;
    }else{
        int mid=(start+end)/2;
        if(start<=index and index<=mid){
            update1(2*node,start,mid,index,val);
        }else{
            update1(2*node+1,mid+1,end,index,val);
        }
        tree1[node]=tree1[2*node] ^ tree1[2*node+1];
    }
}
void update2(int node,int start,int end,int index,int val){
    if(start==end){
        tree2[node]=val;
        c[index]=val;
    }else{
        int mid=(start+end)/2;
        if(start<=index and index<=mid){
            update2(2*node,start,mid,index,val);
        }else{
            update2(2*node+1,mid+1,end,index,val);
        }
        tree2[node]=tree2[2*node] ^ tree2[2*node+1];
    }
}
int query1(int node,int start,int end,int l,int r){
    if(r<start or l>end){
        return 0;
    }
    if(l<=start and end<=r){
        return tree1[node];
    }
    int mid=(start+end)/2;
    int p1=query1(2*node,start,mid,l,r);
    int p2=query1(2*node+1,mid+1,end,l,r);
    return (p1 ^ p2);
}
int query2(int node,int start,int end,int l,int r){
    if(r<start or l>end){
        return 0;
    }
    if(l<=start and end<=r){
        return tree2[node];
    }
    int mid=(start+end)/2;
    int p1=query2(2*node,start,mid,l,r);
    int p2=query2(2*node+1,mid+1,end,l,r);
    return (p1 ^ p2);
}
int main(){
    int n,q;
    cin>>n>>q;

int x=0;
int y=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(i%2==0){
           b[x]=arr[i];
           x++;
        }else{
            c[y]=arr[i];
            y++;
        }
        
    }
  
   build1(1,0,x-1);
   build2(1,0,y-1);
    for(int i=0;i<q;i++){
        int a,b1,c1;
        cin>>a>>b1>>c1;
        if(a==1){
            if((b1-1)%2==0){
                update1(1,0,x-1,(b1-1)/2,c1);
                arr[b1-1]=c1;
            }else{
                update2(1,0,y-1,(b1-2)/2,c1);
                arr[b1-1]=c1;
            }
        }else{
           
            if(c1==b1){
                cout<<arr[b1-1]<<endl;
            }else if(abs(c1-b1)%2==1){
                cout<<0<<endl;
            }else{
           
            if((b1-1)%2==0){
              
                  cout<<query1(1,0,x-1,(b1-1)/2,(c1-1)/2)<<endl;
            }else{
                cout<<query2(1,0,y-1,(b1-2)/2,(c1-2)/2)<<endl;
            }
       
              
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 20 ms 768 KB Output is correct
12 Correct 20 ms 640 KB Output is correct
13 Correct 22 ms 640 KB Output is correct
14 Correct 29 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 998 ms 10084 KB Output is correct
2 Correct 987 ms 10104 KB Output is correct
3 Correct 986 ms 9976 KB Output is correct
4 Correct 930 ms 9720 KB Output is correct
5 Correct 929 ms 9744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 20 ms 768 KB Output is correct
12 Correct 20 ms 640 KB Output is correct
13 Correct 22 ms 640 KB Output is correct
14 Correct 29 ms 640 KB Output is correct
15 Correct 998 ms 10084 KB Output is correct
16 Correct 987 ms 10104 KB Output is correct
17 Correct 986 ms 9976 KB Output is correct
18 Correct 930 ms 9720 KB Output is correct
19 Correct 929 ms 9744 KB Output is correct
20 Correct 811 ms 9728 KB Output is correct
21 Correct 815 ms 9720 KB Output is correct
22 Correct 804 ms 9720 KB Output is correct
23 Correct 951 ms 9728 KB Output is correct
24 Correct 937 ms 9592 KB Output is correct