# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1181357 | nguyn | XORanges (eJOI19_xoranges) | C++20 | 51 ms | 3912 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
struct BIT {
int n;
vector<int> bit;
BIT () {}
BIT (int n) : n(n) {
bit.assign(n + 3, 0);
}
void update(int id, int val) {
for (int i = id; i <= n; i += (i & -i)) bit[i] ^= val;
}
int get(int id) {
int res = 0;
for (int i = id; i; i -= (i & -i)) res ^= bit[i];
return res;
}
int get(int l, int r) {
return get(r) ^ get(l - 1);
}
} bit[2];
int n, q;
int a[N];
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> q;
bit[0] = BIT(n);
bit[1] = BIT(n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
bit[i & 1].update(i, a[i]);
}
while(q--) {
int type;
cin >> type;
if (type == 1) {
int i, j;
cin >> i >> j;
bit[i & 1].update(i, a[i]);
a[i] = j;
bit[i & 1].update(i, a[i]);
}
if (type == 2) {
int l, r;
cin >> l >> r;
if (l & 1) {
if (r & 1) {
cout << bit[1].get(l, r);
}
else {
cout << 0;
}
}
else {
if (r & 1) {
cout << 0;
}
else {
cout << bit[0].get(l, r);
}
}
cout << '\n';
}
}
}
Compilation message (stderr)
# | 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... |