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;
int n, q, i, a, b, quer;
int c[200005];
int seg[2][800020];
void Update(int start=1, int ende=n, int indx=1) {
if (start == ende) {
seg[a&1][indx] = b;
return;
}
int mid = (start+ende)/2;
if (a <= mid) Update(start, mid, 2*indx);
else Update(mid+1, ende, 2*indx+1);
seg[a&1][indx] = seg[a&1][2*indx]^seg[a&1][2*indx+1];
}
int Query(int from, int to, int start=1, int ende=n, int indx=1) {
if (from == start && to == ende) return seg[a&1][indx];
int mid = (start+ende)/2;
if (to <= mid) return Query(from, to, start, mid, 2*indx);
else if (from > mid) return Query(from, to, mid+1, ende, 2*indx+1);
else return Query(from, mid, start, mid, 2*indx)^Query(mid+1, to, mid+1, ende, 2*indx+1);
}
void Build(int start=1, int ende=n, int indx=1) {
if (start == ende) {
seg[start&1][indx] = c[start];
return;
}
int mid = (start+ende)/2;
Build(start, mid, 2*indx);
Build(mid+1, ende, 2*indx+1);
seg[0][indx] = seg[0][2*indx]^seg[0][2*indx+1];
seg[1][indx] = seg[1][2*indx]^seg[1][2*indx+1];
}
int main() {
scanf("%d%d", &n, &q);
for (i=1; i <= n; ++i) scanf("%d", &c[i]);
Build();
while (q--) {
scanf("%d%d%d", &quer, &a, &b);
if (quer == 1) Update();
else if ((a&1) != (b&1)) printf("0\n");
else printf("%d\n", Query(a, b));
}
return 0;
}
Compilation message (stderr)
xoranges.cpp: In function 'int main()':
xoranges.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:43:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | for (i=1; i <= n; ++i) scanf("%d", &c[i]);
| ~~~~~^~~~~~~~~~~~~
xoranges.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d%d", &quer, &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |