This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5;
int a[NMAX + 5];
struct FenwickTree
{
int n;
vector<int>aib;
void build (int _n)
{
n = _n + 1;
aib.resize(n, 0);
}
void update (int pos, int val)
{
for (; pos < n; pos += pos & -pos)
aib[pos] ^= val;
}
int query (int pos)
{
int ret = 0;
for (; pos > 0; pos -= pos & -pos)
ret ^= aib[pos];
return ret;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
FenwickTree aib[2];
aib[0].build(n / 2 + 1);
aib[1].build(n / 2 + 1);
for (int i=2; i<=n+1; i++)
{
cin >> a[i];
aib[i & 1].update(i / 2, a[i]);
}
while (q--)
{
int op, x, y;
cin >> op >> x >> y;
x++;
if (op == 1)
{
int v = (a[x] ^ y);
aib[x & 1].update(x / 2, v);
a[x] = y;
}
else
{
y++;
int ans = 0;
if (x % 2 != y % 2)
{
cout << "0\n";
continue;
}
if (x % 2 == 0)
{
x /= 2, y /= 2;
cout << (aib[0].query(y) ^ aib[0].query(x - 1)) << '\n';
}
else
{
x /= 2, y /= 2;
cout << (aib[1].query(y) ^ aib[1].query(x - 1)) << '\n';
}
}
}
return 0;
}
Compilation message (stderr)
xoranges.cpp: In function 'int main()':
xoranges.cpp:61:17: warning: unused variable 'ans' [-Wunused-variable]
61 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |