#include <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
if(a>b) swap(a,b);
if(a==0) return a+b;
return gcd(b%a,a);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool is_prime(ll n){
ll k=sqrt(n);
if(n==2) return true;
if(n<2||n%2==0||k*k==n) return false;
for(int i=3;i<=k;i+=2){
if(n%i==0){
return false;
}
}
return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
int t=1,n,arr[mxn],q;
struct st{
ll a,b;
};
st tree[4*mxn];
st mrg(st x,st y){
st ans;
ans.a=((x.a)^(y.a));
ans.b=((x.b)^(y.b));
return ans;
}
void build(int node,int l,int r){
if(l==r){
if(l%2==1){
tree[node].a=arr[l];
tree[node].b=0;
}
else{
tree[node].a=0;
tree[node].b=arr[l];
}
return;
}
int m=(l+r)/2;
build(2*node,l,m);
build(2*node+1,m+1,r);
tree[node]=mrg(tree[2*node],tree[2*node+1]);
}
void update(int node,int l,int r,int ind,int val){
if(ind<l||ind>r){
return;
}
if(l==r){
if(l%2==1){
tree[node].a=val;
tree[node].b=0;
}
else{
tree[node].a=0;
tree[node].b=val;
}
return;
}
int m=(l+r)/2;
update(2*node,l,m,ind,val);
update(2*node+1,m+1,r,ind,val);
tree[node]=mrg(tree[2*node],tree[2*node+1]);
}
st query(int node,int l,int r,int ql,int qr){
if(ql>r||qr<l){
st x;
x.a=0,x.b=0;
return x;
}
if(ql<=l&&r<=qr){
return tree[node];
}
int m=(l+r)/2;
st x=query(2*node,l,m,ql,qr);
st y=query(2*node+1,m+1,r,ql,qr);
return mrg(x,y);
}
void solve(){
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
build(1,1,n);
while(q--){
int k,l,r;
cin>>k>>l>>r;
if(k==1){
update(1,1,n,l,r);
}
else{
st ans=query(1,1,n,l,r);
ll k=0;
if((r-l+1)%2==1){
if(l%2==1){
k=ans.a;
}
else{
k=ans.b;
}
}
if((2*(r-(l+1)+1))%2==1){
if((l+1)%2==1){
k^=ans.a;
}
else{
k^=ans.b;
}
}
cout<<k<<endl;
}
}
}
int main(){
IOS;
//cin>>t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 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 |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
10476 KB |
Output is correct |
2 |
Correct |
233 ms |
10400 KB |
Output is correct |
3 |
Correct |
248 ms |
10492 KB |
Output is correct |
4 |
Correct |
186 ms |
10408 KB |
Output is correct |
5 |
Correct |
181 ms |
10396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
588 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
15 |
Correct |
237 ms |
10476 KB |
Output is correct |
16 |
Correct |
233 ms |
10400 KB |
Output is correct |
17 |
Correct |
248 ms |
10492 KB |
Output is correct |
18 |
Correct |
186 ms |
10408 KB |
Output is correct |
19 |
Correct |
181 ms |
10396 KB |
Output is correct |
20 |
Correct |
225 ms |
9788 KB |
Output is correct |
21 |
Correct |
224 ms |
9860 KB |
Output is correct |
22 |
Correct |
209 ms |
9792 KB |
Output is correct |
23 |
Correct |
189 ms |
10424 KB |
Output is correct |
24 |
Correct |
194 ms |
10480 KB |
Output is correct |