#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#define int long long
int tree[(int)(2e5+1)*4],arr[(int)2e5+1];
int n;
void build(int l,int r,int v)
{
if(l==r)
{
tree[v]=arr[l];
}
else
{
int mid=(l+r)/2;
build(l,mid,v*2+1);
build(mid+1,r,v*2+2);
tree[v]=tree[v*2+1]^tree[v*2+2];
}
}
int get(int l,int r,int v,int lq,int rq)
{
if(r<lq||l>rq)
return 0;
if(l>=lq&&r<=rq)
return tree[v];
int mid=(l+r)/2;
return get(l,mid,v*2+1,lq,rq)^get(mid+1,r,v*2+2,lq,rq);
}
void update(int l,int r,int idx,int val,int v)
{
if(l==r)
{
tree[v]=val;
}
else
{
int mid=(l+r)/2;
if(idx<=mid)
update(l,mid,idx,val,v*2+1);
else update(mid+1,r,idx,val,v*2+2);
tree[v]=tree[v*2+1]^tree[v*2+2];
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
int q;
cin>>q;
for(int i=0;i<n*4;i++)
tree[i]=0;
for(int i=0;i<n;i++)
cin>>arr[i];
int idx=0;
map<int,int>map;
int arr2[n];
for(int i=0;i<n;i+=2){
map[i]=idx;
arr2[idx++]=arr[i];
}
for(int i=1;i<n;i+=2){
map[i]=idx;
arr2[idx++]=arr[i];
}
copy(arr2, arr2+n, arr);
build(0,n-1,0);
vector<int>ans;
for(int i=0;i<q;i++)
{
int t;
cin>>t;
if(t==1)
{
cin>>idx;
idx--;
int val;
cin>>val;
idx=map[idx];
update(0,n-1,idx,val,0);
}
else
{
int l,r;
cin>>l>>r;
l--,r--;
if((r-l+1)%2==0)
{
ans.push_back(0);
continue ;
}
l=map[l];
r=map[r];
ans.push_back(get(0,n-1,0,l,r));
}
}
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<endl;
return 0;
}
Compilation message
xoranges.cpp: In function 'int32_t main()':
xoranges.cpp:104:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int i=0;i<ans.size();i++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
9 ms |
940 KB |
Output is correct |
12 |
Correct |
9 ms |
844 KB |
Output is correct |
13 |
Correct |
12 ms |
992 KB |
Output is correct |
14 |
Correct |
12 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
673 ms |
25124 KB |
Output is correct |
2 |
Correct |
664 ms |
25012 KB |
Output is correct |
3 |
Correct |
673 ms |
25184 KB |
Output is correct |
4 |
Correct |
535 ms |
25028 KB |
Output is correct |
5 |
Correct |
535 ms |
25136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
9 ms |
940 KB |
Output is correct |
12 |
Correct |
9 ms |
844 KB |
Output is correct |
13 |
Correct |
12 ms |
992 KB |
Output is correct |
14 |
Correct |
12 ms |
972 KB |
Output is correct |
15 |
Correct |
673 ms |
25124 KB |
Output is correct |
16 |
Correct |
664 ms |
25012 KB |
Output is correct |
17 |
Correct |
673 ms |
25184 KB |
Output is correct |
18 |
Correct |
535 ms |
25028 KB |
Output is correct |
19 |
Correct |
535 ms |
25136 KB |
Output is correct |
20 |
Correct |
554 ms |
23680 KB |
Output is correct |
21 |
Correct |
517 ms |
23684 KB |
Output is correct |
22 |
Correct |
508 ms |
23736 KB |
Output is correct |
23 |
Correct |
536 ms |
24936 KB |
Output is correct |
24 |
Correct |
536 ms |
24944 KB |
Output is correct |