-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path339D.cpp
More file actions
79 lines (63 loc) · 1.46 KB
/
339D.cpp
File metadata and controls
79 lines (63 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// #define DEBUG
#define MAXN 2000000000
#define llu unsigned long long
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
vector<int> a;
vector<int> segtree;
void build(int i, int l, int r, bool OR) {
if (l == r) {
segtree[i] = a[l];
return;
}
int m = (l + r) >> 1;
build(2 * i, l, m, !OR);
build(2 * i + 1, m + 1, r, !OR);
if (OR)
segtree[i] = segtree[2 * i] | segtree[2 * i + 1];
else
segtree[i] = segtree[2 * i] ^ segtree[2 * i + 1];
}
void update(int i, int qi, int q, int l, int r, bool OR) {
if (l == r) {
a[l] = q;
segtree[i] = q;
return;
}
int m = (l + r) >> 1;
if (qi <= m)
update(2 * i, qi, q, l, m, !OR);
else
update(2 * i + 1, qi, q, m + 1, r, !OR);
if (OR)
segtree[i] = segtree[2 * i] | segtree[2 * i + 1];
else
segtree[i] = segtree[2 * i] ^ segtree[2 * i + 1];
}
int main() {
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int length, num_query;
cin >> length >> num_query;
a.resize(1 << length);
segtree.resize(1 << (length + 1));
for (auto &n : a)
cin >> n;
vector<pair<int, int>> query(num_query);
for (auto &p : query)
cin >> p.first >> p.second;
build(1, 0, a.size() - 1, length % 2);
for (auto &q : query) {
update(1, q.first - 1, q.second, 0, a.size() - 1, length % 2);
cout << segtree[1] << endl;
}
return 0;
}