이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nmax = 5001;
struct AINT {
int aint[nmax * 4];
void init() {
memset(aint, 0, sizeof(aint));
}
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 * 2, st, mid, poz, val);
} else {
update(nod * 2 + 1, mid + 1, dr, poz, val);
}
aint[nod] = (aint[nod * 2] ^ aint[nod * 2 + 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 * 2, st, mid, l, min(r, mid));
}
if(r > mid) {
a2 = query(nod * 2 + 1, mid + 1, dr, max(l, mid + 1), r);
}
return (a1 ^ a2);
}
};
int main() {
AINT s1, s2;
/*
for(int i = 1; i <= 5; i ++) {
s1.update(1, 1, 5, i, i);
}
for(int i = 1; i <= 5; i ++) {
cout << s1.query(1, 1, 5, i, i) << ' ';
}
cout << '\n';
*/
s1.init();
s2.init();
int n, q;
cin >> n >> q;
int ok = n % 2;
for(int i = 1; i <= n; i ++) {
int a;
cin >> a;
if(i % 2 == 0) {
s1.update(1, 1, n / 2, i / 2, a);
// cout << s1.query(1, 1, n / 2 + 1, i / 2, i / 2) << " ";
} else {
s2.update(1, 1, n / 2 + ok, i / 2 + 1, a);
// cout << s2.query(1, 1, n / 2 + 1, i / 2 + 1, i / 2 + 1) << " ";
}
}
// cout << '\n';
// cout << "sirul: ";
/*
for(int ii = 1; ii <= n; ii ++) {
if(ii % 2 == 0) {
cout << s1.query(1, 1, n / 2, ii / 2, ii / 2) << " ";
} else {
cout << s2.query(1, 1, n / 2 + ok, ii / 2 + 1, ii / 2 + 1) << " ";
}
}
cout << '\n';
*/
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, a / 2, b);
} else {
s2.update(1, 1, n / 2 + ok, 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, a / 2, b / 2) << '\n';
} else {
cout << s2.query(1, 1, n / 2 + ok, a / 2 + 1, b / 2 + 1) << '\n';
}
}
}
return 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... |