#include <bits/stdc++.h>
using namespace std;
int seg1[400005], seg2[400005], a[200005];
void build1(int i, int l, int r)
{
if (l==r)
{
seg1[i]=a[l*2-1];
return;
}
int m=(l+r)/2;
build1(i*2, l, m);
build1(i*2+1, m+1, r);
seg1[i]=seg1[i*2]^seg1[i*2+1];
}
void build2(int i, int l, int r)
{
if (l==r)
{
seg2[i]=a[l*2];
return;
}
int m=(l+r)/2;
build2(i*2, l, m);
build2(i*2+1, m+1, r);
seg2[i]=seg2[i*2]^seg2[i*2+1];
}
void update1(int i, int l, int r, int y, int z)
{
if (l==r)
{
seg1[i]=a[l*2-1]=z;
return;
}
int m=(l+r)/2;
y<=m?update1(i*2, l, m, y, z):update1(i*2+1, m+1, r, y, z);
seg1[i]=seg1[i*2]^seg1[i*2+1];
}
void update2(int i, int l, int r, int y, int z)
{
if (l==r)
{
seg2[i]=a[l*2]=z;
return;
}
int m=(l+r)/2;
y<=m?update2(i*2, l, m, y, z):update2(i*2+1, m+1, r, y, z);
seg2[i]=seg2[i*2]^seg2[i*2+1];
}
int query1(int i, int l, int r, int ql, int qr)
{
if (ql<=l && r<=qr)
return seg1[i];
int m=(l+r)/2, x=0;
if (ql<=m && l<=qr)
x^=query1(i*2, l, m, ql, qr);
if (ql<=r && m<qr)
x^=query1(i*2+1, m+1, r, ql, qr);
return x;
}
int query2(int i, int l, int r, int ql, int qr)
{
if (ql<=l && r<=qr)
return seg2[i];
int m=(l+r)/2, x=0;
if (ql<=m && l<=qr)
x^=query2(i*2, l, m, ql, qr);
if (ql<=r && m<qr)
x^=query2(i*2+1, m+1, r, ql, qr);
return x;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for (int i=1; i<=n; i++)
cin >> a[i];
build1(1, 1, (n+1)/2);
if (n>1)
build2(1, 1, n/2);
for (int i=1; i<=q; i++)
{
int x, y, z;
cin >> x >> y >> z;
if (x==1)
y&1?update1(1, 1, (n+1)/2, (y+1)/2, z):update2(1, 1, n/2, y/2, z);
else if ((z-y)&1)
cout << 0 << '\n';
else
cout << ((z-y)&1?0:y&1?query1(1, 1, (n+1)/2, (y+1)/2, (z+1)/2):query2(1, 1, n/2, y/2, z/2)) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
448 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
440 KB |
Output is correct |
14 |
Correct |
3 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
9168 KB |
Output is correct |
2 |
Correct |
102 ms |
9168 KB |
Output is correct |
3 |
Correct |
104 ms |
9204 KB |
Output is correct |
4 |
Correct |
99 ms |
8908 KB |
Output is correct |
5 |
Correct |
99 ms |
8848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
448 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
440 KB |
Output is correct |
14 |
Correct |
3 ms |
564 KB |
Output is correct |
15 |
Correct |
104 ms |
9168 KB |
Output is correct |
16 |
Correct |
102 ms |
9168 KB |
Output is correct |
17 |
Correct |
104 ms |
9204 KB |
Output is correct |
18 |
Correct |
99 ms |
8908 KB |
Output is correct |
19 |
Correct |
99 ms |
8848 KB |
Output is correct |
20 |
Correct |
121 ms |
8908 KB |
Output is correct |
21 |
Correct |
113 ms |
8856 KB |
Output is correct |
22 |
Correct |
105 ms |
8912 KB |
Output is correct |
23 |
Correct |
99 ms |
8824 KB |
Output is correct |
24 |
Correct |
97 ms |
8820 KB |
Output is correct |