From f414f95e0aa4b2991ad0026288c4519a33cefab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20=28Lua=29=20Guimar=C3=A3es?= Date: Fri, 10 Oct 2025 14:34:21 -0300 Subject: [PATCH] SegTree fix for custom join --- Library/Data Structures/SegTree.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Data Structures/SegTree.cpp b/Library/Data Structures/SegTree.cpp index b7fee09..47b481a 100644 --- a/Library/Data Structures/SegTree.cpp +++ b/Library/Data Structures/SegTree.cpp @@ -4,13 +4,13 @@ using namespace std; template struct SegTree { vector seg; int N; - T NEUTRO = 0; - SegTree(int n) : N(n) { seg.assign(4*n, NEUTRO); } - SegTree(vector &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 &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; @@ -48,5 +48,5 @@ template 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*/ \ No newline at end of file +**Update Join, IDENTITY and Update if needed** +***************************LATEX_IGNORED_END*/