// author: erray
#undef DEBUG
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename F> string to_string(pair<T, F> p);
template<typename T, typename F, typename Tr> string to_string(tuple<T, F, Tr> p);
template<typename T, typename F, typename Tr, typename Th> string to_string(tuple<T, F, Tr, Th> p);
string to_string(string s) {
return '"' + s + '"';
}
string to_string(char c) {
return (string) "'" + c + "'";
}
string to_string(const char* p) {
return to_string((string) p);
}
string to_string(bool B) {
return (B ? "true" : "false");
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < (int) v.size(); ++i) {
if ((int) res.size() > 1) res += ", ";
res += to_string(v[i]);
}
res += "}";
return res;
}
template<size_t T> string to_string(bitset<T> bs) {
return bs.to_string();
}
template<typename T> string to_string(T v) {
string res = "{";
for (auto& el : v) {
if ((int) res.size() > 1) res += ", ";
res += to_string(el);
}
res += "}";
return res;
}
template<typename T, typename F> string to_string(pair<T, F> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
template<typename T, typename F, typename Tr> string to_string(tuple<T, F, Tr> p) {
return '(' + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ')';
}
template<typename T, typename F, typename Tr, typename Th> string to_string(tuple<T, F, Tr, Th> p) {
return '(' + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define debug(...) (void) 37
#endif
class bit {
public:
vector<int> tree;
int n;
bit(int _n) : n(_n) {
tree.resize(n + 1);
}
int get(int ind) {
if (ind == -1) return 0;
++ind;
int res = 0;
while (ind) {
res ^= tree[ind];
ind -= ind & -ind;
}
return res;
}
int get(int l, int r) {
return get(r) ^ get(l - 1);
}
void modify(int ind, int val) {
int old = get(ind, ind);
++ind;
while (ind <= n) {
tree[ind] ^= old;
tree[ind] ^= val;
ind += ind & -ind;
}
}
};
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
bit b0(n), b1(n);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (i % 2) {
b1.modify(i, x);
} else b0.modify(i, x);
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
if (t == 2) {
--l; --r;
if ((r - l + 1) % 2 == 0) {
cout << 0;
} else if (l % 2) {
cout << b1.get(l, r);
} else {
cout << b0.get(l, r);
}
cout << '\n';
} else {
--l;
if (l % 2) {
b1.modify(l, r);
} else {
b0.modify(l, r);
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
6136 KB |
Output is correct |
2 |
Correct |
110 ms |
5112 KB |
Output is correct |
3 |
Correct |
110 ms |
5216 KB |
Output is correct |
4 |
Correct |
103 ms |
5112 KB |
Output is correct |
5 |
Correct |
103 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
118 ms |
6136 KB |
Output is correct |
16 |
Correct |
110 ms |
5112 KB |
Output is correct |
17 |
Correct |
110 ms |
5216 KB |
Output is correct |
18 |
Correct |
103 ms |
5112 KB |
Output is correct |
19 |
Correct |
103 ms |
5112 KB |
Output is correct |
20 |
Correct |
108 ms |
4472 KB |
Output is correct |
21 |
Correct |
108 ms |
4472 KB |
Output is correct |
22 |
Correct |
118 ms |
4472 KB |
Output is correct |
23 |
Correct |
106 ms |
5112 KB |
Output is correct |
24 |
Correct |
115 ms |
5156 KB |
Output is correct |