#include <bits/stdc++.h>
using namespace std;
struct arbore_de_intervale
{
int par,imp;
};
arbore_de_intervale ai[200005];
int n,q,v[200005];
void update(int poz, int val, int nod, int a, int b)
{
if(a==b)
{
if(a%2==1)
{
ai[nod].imp = val;
ai[nod].par = 0;
}
else
{
ai[nod].par = val;
ai[nod].imp = 0;
}
return;
}
int mij = (a+b)>>1;
if(poz<=mij)
{
update(poz,val,nod*2,a,mij);
}
else
{
update(poz,val,nod*2+1,mij+1,b);
}
ai[nod].par = (ai[nod*2].par ^ ai[nod*2+1].par);
ai[nod].imp = (ai[nod*2].imp ^ ai[nod*2+1].imp);
}
int query(int qa, int qb, int paritate, int nod, int a, int b)
{
if(qa<=a && qb>=b)
{
if(paritate%2==0)
{
return ai[nod].par;
}
return ai[nod].imp;
}
int mij = (a+b)>>1;
int rez1 = 0, rez2 = 0;
if(qa<=mij)
{
rez1 = query(qa,qb,paritate,nod*2,a,mij);
}
if(qb>mij)
{
rez2 = query(qa,qb,paritate,nod*2+1,mij+1,b);
}
return (rez1 ^ rez2);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
for(int i=1; i<=n; i++)
{
cin>>v[i];
update(i,v[i],1,1,n);
}
for(int i=1; i<=q; i++)
{
int t;
cin>>t;
if(t==1)
{
int poz,val;
cin>>poz>>val;
update(poz,val,1,1,n);
}
else
{
int x,y;
cin>>x>>y;
if((y-x+1)%2==0)
{
cout<<0<<'\n';
continue;
}
if(x%2==1)
{
cout<<query(x,y,1,1,1,n)<<'\n';
}
else
{
cout<<query(x,y,0,1,1,n)<<'\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
236 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 |
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 |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
236 KB |
Output is correct |
4 |
Correct |
1 ms |
332 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 |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
236 KB |
Output is correct |
4 |
Correct |
1 ms |
332 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 |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
4 ms |
588 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
15 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
16 |
Halted |
0 ms |
0 KB |
- |