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 <iostream>
using namespace std;
const int nmax = 5001;
int f[101];
struct AINT {
int aint[nmax * 4];
void update(int nod, int st, int dr, int poz, int val) {
if(st == dr) {
aint[nod] = val;
return;
}
int mid = (st + dr) / 2;
if(poz <= mid) {
update(nod << 1, st, mid, poz, val);
} else {
update(nod << 1 + 1, mid + 1, dr, poz, val);
}
aint[nod] = (aint[nod << 1] ^ aint[nod << 1 + 1]);
}
int query(int nod, int st, int dr, int l, int r) {
if(l <= st && dr <= r) {
return aint[nod];
}
int mid = (st + dr) / 2, a1 = 0, a2 = 0;
if(l <= mid) {
a1 = query(nod << 1, st, mid, l, min(r, mid));
}
if(r > mid) {
a2 = query(nod << 1 + 1, mid + 1, dr, max(l, mid + 1), r);
}
return (a1 ^ a2);
}
};
int main() {
AINT s1, s2;
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i ++) {
int a;
cin >> a;
if(i % 2 == 0) {
s1.update(1, 1, n / 2 + 1, i / 2, a);
} else {
s2.update(1, 1, n / 2 + 1, i / 2 + 1, a);
}
}
for(int i = 1; i <= q; i ++) {
int t, a, b;
cin >> t >> a >> b;
if(t == 1) {
if(a % 2 == 0) {
s1.update(1, 1, n / 2 + 1, a / 2, b);
} else {
s2.update(1, 1, n / 2 + 1, a / 2 + 1, b);
}
} else {
if((b - a + 1) % 2 == 0) {
cout << "0\n";
} else if(a % 2 == 0) {
cout << s1.query(1, 1, n / 2 + 1, a / 2, b / 2) << '\n';
} else {
cout << s2.query(1, 1, n / 2 + 1, a / 2 + 1, b / 2 + 1) << '\n';
}
}
/*
cout << "sirul: ";
for(int ii = 1; ii <= n; ii ++) {
if(ii % 2 == 0) {
cout << s1.query(1, 1, n / 2 + 1, ii / 2, ii / 2) << " ";
} else {
cout << s2.query(1, 1, n / 2 + 1, ii / 2 + 1, ii / 2 + 1) << " ";
}
}
cout << '\n';
*/
}
return 0;
}
Compilation message (stderr)
xoranges.cpp: In member function 'void AINT::update(int, int, int, int, int)':
xoranges.cpp:21:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
21 | update(nod << 1 + 1, mid + 1, dr, poz, val);
| ~~^~~
xoranges.cpp:23:49: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
23 | aint[nod] = (aint[nod << 1] ^ aint[nod << 1 + 1]);
| ~~^~~
xoranges.cpp: In member function 'int AINT::query(int, int, int, int, int)':
xoranges.cpp:35:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
35 | a2 = query(nod << 1 + 1, mid + 1, dr, max(l, mid + 1), r);
| ~~^~~
# | 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... |