#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vei;
typedef vector<vei> vevei;
#define coa \
for (auto i : a) { \
cout << i << ' '; \
} \
cout << '\n';
#define cia \
for (auto& i : a) { \
cin >> a; \
}
#define cna \
int n; \
cin >> n; \
vector<int> a(n); \
for (int i = 0; i < n; i++) { \
cin >> a[i]; \
}
#define cnka \
int n, k; \
cin >> n >> k; \
vector<int> a(n); \
for (int i = 0; i < n; i++) { \
cin >> a[i]; \
}
#define cnab \
int n; \
cin >> n; \
vector<int> a(n); \
for (int i = 0; i < n; i++) { \
cin >> a[i]; \
} \
vector<int> b(n); \
for (int i = 0; i < n; i++) { \
cin >> b[i]; \
}
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) a.size()
#define con cout << "NO\n"
#define coe cout << "YES\n";
#define str string
#define pb push_back
#define ff first
#define sc second
#define pii pair<int, int>
#define mxe max_element
#define mne min_element
#define stf shrink_to_fit
#define f(i, l, r) for (int i = (l); i < (r); i++)
#define double ld
#define int long long
struct segtree {
int n;
vector<int> a;
vector<int> t;
segtree() = default;
segtree(int n_, vector<int> a_) {
n = n_;
a = a_;
t.assign(4 * n, 0);
build(1, 0, n);
}
void build(int v, int tl, int tr) {
if (tl + 1 == tr) {
t[v] = a[tl];
return;
}
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm, tr);
t[v] = (t[v * 2] ^ t[v * 2 + 1]);
}
void upd(int v, int tl, int tr, int pos, int val) {
if (tl + 1 == tr) {
t[v] = val;
return;
}
int tm = (tl + tr) / 2;
if (pos < tm) upd(v * 2, tl, tm, pos, val);
else upd(v * 2 + 1, tm, tr, pos, val);
t[v] = (t[v * 2] ^ t[v * 2 + 1]);
}
int req(int v, int tl, int tr, int l, int r) {
if (l <= tl && tr <= r) return t[v];
if (tr <= l || tl >= r) return 0;
int tm = (tl + tr) / 2;
return (req(v * 2, tl, tm, l, r) ^ req(v * 2 + 1, tm, tr, l, r));
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, q; cin >> n >> q;
vector<int> a(n);
for (auto& u : a) cin >> u;
vector<int> ch, nch;
f(i, 0, n) {
if (i % 2 == 0) ch.pb(a[i]);
else nch.pb(a[i]);
}
segtree sg0(sz(ch), ch), sg1(sz(nch), nch);
while (q--) {
int t; cin >> t;
if (t == 1) {
int p, v; cin >> p >> v;
p--;
if (p % 2 == 0) {
sg0.upd(1, 0, sz(ch), p / 2, v);
}
else {
sg1.upd(1, 0, sz(nch), p / 2, v);
}
}
else {
int l, r; cin >> l >> r;
l--; r--;
if ((r - l + 1) % 2 == 0) {
cout << "0\n";
}
else {
if (l % 2 == 0) {
cout << sg0.req(1, 0, sz(ch), l / 2, r / 2 + 1) << '\n';
}
else {
cout << sg1.req(1, 0, sz(nch), l / 2, r / 2 + 1) << '\n';
}
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
18092 KB |
Output is correct |
2 |
Correct |
136 ms |
18004 KB |
Output is correct |
3 |
Correct |
135 ms |
18148 KB |
Output is correct |
4 |
Correct |
102 ms |
17708 KB |
Output is correct |
5 |
Correct |
112 ms |
17704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
720 KB |
Output is correct |
15 |
Correct |
117 ms |
18092 KB |
Output is correct |
16 |
Correct |
136 ms |
18004 KB |
Output is correct |
17 |
Correct |
135 ms |
18148 KB |
Output is correct |
18 |
Correct |
102 ms |
17708 KB |
Output is correct |
19 |
Correct |
112 ms |
17704 KB |
Output is correct |
20 |
Correct |
129 ms |
17904 KB |
Output is correct |
21 |
Correct |
119 ms |
17876 KB |
Output is correct |
22 |
Correct |
150 ms |
17852 KB |
Output is correct |
23 |
Correct |
106 ms |
17704 KB |
Output is correct |
24 |
Correct |
115 ms |
17720 KB |
Output is correct |