#include <bits/stdc++.h>
using namespace std;
struct fenwick {
vector<int> fenw;
int n;
fenwick(int n_) : n(n_) {
fenw.resize(n);
}
void upd(int u, int x) {
for (; u < n; u |= u + 1) fenw[u] ^= x;
}
int qry(int u) {
int xr = 0;
for (; u >= 0; u = (u & (u + 1)) - 1) xr ^= fenw[u];
return xr;
}
int qry(int l, int r) {
return qry(r) ^ qry(l - 1);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n);
fenwick bit1(n), bit2(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i & 1) bit2.upd(i, a[i]);
else bit1.upd(i, a[i]);
}
while (q--) {
int t, l, u;
cin >> t >> l >> u;
if (t == 1) {
--l;
if (l & 1) bit2.upd(l, u ^ a[l]);
else bit1.upd(l, u ^ a[l]);
a[l] = u;
} else {
--l, --u;
if (u - l & 1) cout << "0\n";
else cout << (l & 1 ? bit2.qry(l, u) : bit1.qry(l, u)) << '\n';
}
}
}
Compilation message
xoranges.cpp: In function 'int main()':
xoranges.cpp:45:19: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
45 | if (u - l & 1) cout << "0\n";
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
472 KB |
Output is correct |
13 |
Correct |
3 ms |
472 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
8652 KB |
Output is correct |
2 |
Correct |
111 ms |
8640 KB |
Output is correct |
3 |
Correct |
102 ms |
8692 KB |
Output is correct |
4 |
Correct |
96 ms |
8292 KB |
Output is correct |
5 |
Correct |
94 ms |
8380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
472 KB |
Output is correct |
13 |
Correct |
3 ms |
472 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
122 ms |
8652 KB |
Output is correct |
16 |
Correct |
111 ms |
8640 KB |
Output is correct |
17 |
Correct |
102 ms |
8692 KB |
Output is correct |
18 |
Correct |
96 ms |
8292 KB |
Output is correct |
19 |
Correct |
94 ms |
8380 KB |
Output is correct |
20 |
Correct |
100 ms |
8420 KB |
Output is correct |
21 |
Correct |
105 ms |
8340 KB |
Output is correct |
22 |
Correct |
86 ms |
8408 KB |
Output is correct |
23 |
Correct |
91 ms |
8420 KB |
Output is correct |
24 |
Correct |
95 ms |
8240 KB |
Output is correct |