-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegmentGenerico.cpp
More file actions
126 lines (111 loc) · 3.84 KB
/
Copy pathsegmentGenerico.cpp
File metadata and controls
126 lines (111 loc) · 3.84 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
- Science is knowledge which we understand so well
that we can teach it to a computer; and if we don’t
fully understand something, it is an art to deal with it.
- El trabajo duro supera al talento cuando el talento no trabaja duro.
- Los desafios son los que hacen la vida interesante y superarlos es
lo que hace a la vida significativa.
- Para sentirse vivo se necesita una meta en la que trabajar.
*/
typedef long long ll;
#define srt(a) sort((a).begin(),(a).end());
#define srtR(a) sort((a).rbegin(),(a).rend());
#include <bits/stdc++.h>
using namespace std;
// >>>>>>> Implement
// Example of a Segment tree of Xor
struct Node {
ll a = 0;
};
Node e() {
Node node;
return node;
}
Node op(Node a, Node b) {
Node node;
node.a = a.a ^ b.a;
return node;
}
// >>>>>>>> Implement
struct segtree {
vector<Node> nodes;
ll n;
void init(int n) {
auto a = vector<Node>(n, e());
init(a);
}
void init(vector<Node>& initial) {
nodes.clear();
n = initial.size();
int size = 1;
while (size < n) {
size *= 2;
}
nodes.resize(size * 2);
build(0, 0, n-1, initial);
}
void build(int i, int sl, int sr, vector<Node>& initial) {
if (sl == sr) {
nodes[i] = initial[sl];
} else {
ll mid = (sl + sr) >> 1;
build(i*2+1, sl, mid, initial);
build(i*2+2, mid+1,sr,initial);
nodes[i] = op(nodes[i*2+1], nodes[i*2+2]);
}
}
void update(int i, int sl, int sr, int pos, Node node) {
if (sl <= pos && pos <= sr) {
if (sl == sr) {
nodes[i] = node;
} else {
int mid = (sl + sr) >> 1;
update(i * 2 + 1, sl, mid, pos, node);
update(i * 2 + 2, mid + 1, sr, pos, node);
nodes[i] = op(nodes[i*2+1], nodes[i*2+2]);
}
}
}
void update(int pos, Node node) {
update(0, 0, n - 1, pos, node);
}
Node query(int i, int sl, int sr, int l, int r) {
if (l <= sl && sr <= r) {
return nodes[i];
} else if(sr < l || r < sl) {
return e();
} else {
int mid = (sl + sr) / 2;
auto a = query(i * 2 + 1, sl, mid, l, r);
auto b = query(i * 2 + 2, mid + 1, sr, l, r);
return op(a, b);
}
}
Node query(int l, int r) {
return query(0, 0, n - 1, l, r);
}
Node get(int i) {
return query(i, i);
}
};
signed main (){
ios::sync_with_stdio(false);cin.tie(0);
return 0;
}
// :-==-. .:..
// .+%@@@@@@#- -*%@@@@#+.
// .%@@@@@@@@@@%*=--:.....::--+#@@@@@@@@@@@=
// +@@@@@@@%*-. .-*%@@@@@@@%
// +@@@@@%=. .=%@@@@@@.
// -@@@@*. .+@@@@%
// +@@+ .. =@@%:
// -* :*%@@@*. :+#%#+. +#:
// =. =@@@*=+@% :%@##@@@+ .+
// + -@@@@. #@: :----- *@= +@@@+ +
// .+ #@@@@#+*@%. *@@@@%. +@#:-#@@@@: =.
// .= @@@@@@@@+ .=*: :@@@@@@@@= -:
// + :**%@%*: .-=+-- :#@@%**+ +
// +.---:. .----- .=
// := +.
// :=-. .-=:
// .:-----------:.