# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
455330 | kkk | XORanges (eJOI19_xoranges) | C++14 | 183 ms | 20232 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
long long a[1000003],tree[4000000][3];
void build_tree(long long l,long long r,long long ind)
{
if(l==r)
{
if(l%2==0)tree[ind][0]=a[l];
else tree[ind][1]=a[l];
return;
}
long long mid=(l+r)/2;
build_tree(l,mid,2*ind);
build_tree(mid+1,r,2*ind+1);
tree[ind][0]=(tree[2*ind][0]^tree[2*ind+1][0]);
tree[ind][1]=(tree[2*ind][1]^tree[2*ind+1][1]);
}
void update(long long l,long long r,long long pos,long long val,long long ind)
{
if(pos>r || pos<l)return;
if(l==r)
{
if(l%2==0)tree[ind][0]=val;
else tree[ind][1]=val;
return;
}
long long mid=(l+r)/2;
update(l,mid,pos,val,2*ind);
update(mid+1,r,pos,val,2*ind+1);
tree[ind][0]=(tree[2*ind][0]^tree[2*ind+1][0]);
tree[ind][1]=(tree[2*ind][1]^tree[2*ind+1][1]);
}
long long query(long long le,long long ri,long long l,long long r,long long ind,int t)
{
if(le>r || ri<l)return 0;
if(l<=le && ri<=r)
{
if(t==0)return tree[ind][0];
else return tree[ind][1];
}
long long mid=(le+ri)/2, t2;
return (query(le,mid,l,r,2*ind,t)^query(mid+1,ri,l,r,2*ind+1,t));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n,m,q,j,i,b,ans=0,t,l,r;
cin>>n>>q;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
build_tree(1,n,1);
for(i=0;i<q;i++)
{
cin>>t;
if(t==1)
{
cin>>l>>r;
update(1,n,l,r,1);
}
else
{
cin>>l>>r;
if((r-l+1)%2==0)
{
cout<<0<<endl;
continue;
}
cout<<query(1,n,l,r,1,l%2)<<endl;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |