#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10, SQ = 400;
long long n, q, a[N], dp[2][N];
int ans(int l, int r) {
if ((r - l) & 1 == 0)
return 0;
int res = 0;
int l1 = ((l + SQ - 1) / SQ) & SQ, r1 = (r / SQ) * SQ;
if (r1 > l1) {
for (int i = l; i < l1; i += 2)
res ^= a[i];
for (int i = l1; i < r1; i++)
res ^= dp[l & 1][i];
for (int i = r1 + (l & 1); i < r; i += 2)
res ^= a[i];
}
else
for (int i = l; i < r; i += 2)
res ^= a[i];
return res;
}
void input() {
cin >> n >> q;
for (int i = 0; i < n; i++)
cin >> a[i];
}
void solve() {
for (int i = 0; i < q; i++) {
int op;
cin >> op;
if (op == 1) {
int j, v;
cin >> j >> v;
j--;
dp[j & 1][j / SQ] ^= a[j] ^ v;
a[j] = v;
}
else {
int l, r;
cin >> l >> r;
cout << ans(l - 1, r) << '\n';
}
}
}
int main() {
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
input();
solve();
return 0;
}
Compilation message
xoranges.cpp: In function 'int ans(int, int)':
xoranges.cpp:8:21: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
8 | if ((r - l) & 1 == 0)
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
5976 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |