#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000
struct Segtree{
int n;
vector<int> tr, ar;
Segtree(int si){
n = si;
tr.assign(4 * n, 0);
}
void build(int v, int l, int r){
if (l == r){
tr[v] = ar[l];
}
else{
int mid = (l + r) / 2;
build(v * 2, l, mid);
build(v * 2 + 1, mid + 1, r);
tr[v] = tr[v * 2] ^ tr[v * 2 + 1];
}
}
void update(int v, int l, int r, int pos, int nval){
if (l == r){
tr[v] = nval;
}
else{
int mid = (l + r) / 2;
if (pos <= mid){
update(v * 2, l, mid, pos, nval);
}
else{
update(v * 2 + 1, mid + 1, r, pos, nval);
}
tr[v] = tr[v * 2] ^ tr[v * 2 + 1];
}
}
int query(int v, int l, int r, int ql, int qr){
if (r < ql || l > qr){
return 0;
}
else if (ql <= l && r <= qr){
return tr[v];
}
else{
int mid = (l + r) / 2;
return query(v * 2, l, mid, ql, qr) ^ query(v * 2 + 1, mid + 1, r, ql, qr);
}
}
};
int main(){
int n, a, q, ty, l, r;
cin>>n>>q;
Segtree sodd(n), seven(n);
for (int i = 0; i < n; i++){
cin>>a;
if (i % 2 == 0){
seven.update(1, 0, n - 1, i, a);
}
else{
sodd.update(1, 0, n - 1, i, a);
}
}
for (int i = 0; i < q; i++){
cin>>ty>>l>>r;
if (ty == 1){
l--;
if (l % 2 == 0){
seven.update(1, 0, n - 1, l, r);
}
else{
sodd.update(1, 0, n - 1, l, r);
}
}
else{
l--, r--;
if ((r - l + 1) % 2 == 0){
cout<<0<<"\n";
}
else{
if (l % 2 == 0){
cout<<seven.query(1, 0, n - 1, l, r);
}
else{
cout<<sodd.query(1, 0, n - 1, l, r);
}
cout<<"\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
412 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
412 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
348 KB |
Output is correct |
12 |
Correct |
9 ms |
604 KB |
Output is correct |
13 |
Correct |
11 ms |
604 KB |
Output is correct |
14 |
Correct |
9 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
368 ms |
7728 KB |
Output is correct |
2 |
Correct |
439 ms |
7988 KB |
Output is correct |
3 |
Correct |
366 ms |
7724 KB |
Output is correct |
4 |
Correct |
390 ms |
7712 KB |
Output is correct |
5 |
Correct |
382 ms |
7856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
412 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
348 KB |
Output is correct |
12 |
Correct |
9 ms |
604 KB |
Output is correct |
13 |
Correct |
11 ms |
604 KB |
Output is correct |
14 |
Correct |
9 ms |
604 KB |
Output is correct |
15 |
Correct |
368 ms |
7728 KB |
Output is correct |
16 |
Correct |
439 ms |
7988 KB |
Output is correct |
17 |
Correct |
366 ms |
7724 KB |
Output is correct |
18 |
Correct |
390 ms |
7712 KB |
Output is correct |
19 |
Correct |
382 ms |
7856 KB |
Output is correct |
20 |
Correct |
300 ms |
7252 KB |
Output is correct |
21 |
Correct |
291 ms |
7200 KB |
Output is correct |
22 |
Correct |
361 ms |
7200 KB |
Output is correct |
23 |
Correct |
372 ms |
7716 KB |
Output is correct |
24 |
Correct |
385 ms |
7724 KB |
Output is correct |