Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Library/Data Structures/SegTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ using namespace std;
template<typename T> struct SegTree {
vector<T> seg;
int N;
T NEUTRO = 0;
SegTree(int n) : N(n) { seg.assign(4*n, NEUTRO); }
SegTree(vector<T> &lista) : N(lista.size()) { seg.assign(4*N); build(1, 0, N-1, lista); }
T IDENTITY = T();
SegTree(int n) : N(n) { seg.assign(4*n, IDENTITY); }
SegTree(vector<T> &lista) : N(lista.size()) { seg.assign(4*N, IDENTITY); build(1, 0, N-1, lista); }
T join(T lv, T rv){ return lv + rv; }

T query(int no, int l, int r, int a, int b){
if(b < l || r < a) return NEUTRO;
if(b < l || r < a) return IDENTITY;
if(a <= l && r <= b) return seg[no];
int m=(l+r)/2, e=no*2, d=e+1;

Expand Down Expand Up @@ -48,5 +48,5 @@ template<typename T> struct SegTree {
Build: O(N)
Query: O(log N) | seg.query(l, r);
Update: O(log N) | seg.update(i, v);
**Update Join, NEUTRO and Update if needed**
***************************LATEX_IGNORED_END*/
**Update Join, IDENTITY and Update if needed**
***************************LATEX_IGNORED_END*/