From 1e1145405dd521352954e27e41a61972fd3d1c58 Mon Sep 17 00:00:00 2001 From: Bruno Freitas Tissei <bft15@inf.ufpr.br> Date: Sun, 25 Feb 2018 12:08:50 -0300 Subject: [PATCH] Fix segment trees Signed-off-by: Bruno Freitas Tissei <bft15@inf.ufpr.br> --- structure/lazy_segment_tree.cpp | 4 ++-- structure/segment_tree.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/structure/lazy_segment_tree.cpp b/structure/lazy_segment_tree.cpp index 61ecf39..b06b18d 100644 --- a/structure/lazy_segment_tree.cpp +++ b/structure/lazy_segment_tree.cpp @@ -8,7 +8,7 @@ * Complexity (Space): O(n) */ -int N, tree[2 * MAX], lazy[2 * MAX], v[MAX]; +int N, tree[4 * MAX], lazy[4 * MAX], v[MAX]; // Build tree with elements from v void build_tree(int node = 1, int a = 0, int b = N) { @@ -63,7 +63,7 @@ void update_tree(int i, int j, int val, int node = 1, int a = 0, int b = N) { tree[node] = tree[node * 2] + tree[node * 2 + 1]; } -// Return sum from i to j +// Return sum of [i,j] int query_tree(int i, int j, int node = 1, int a = 0, int b = N) { if (a > b || a > j || b < i) return 0; diff --git a/structure/segment_tree.cpp b/structure/segment_tree.cpp index e825ed9..d0f7762 100644 --- a/structure/segment_tree.cpp +++ b/structure/segment_tree.cpp @@ -8,7 +8,7 @@ * Complexity (Space): O(n) */ -int N, tree[2 * MAX], v[MAX]; +int N, tree[4 * MAX], v[MAX]; // Build tree with elements from v void build_tree(int node = 1, int a = 0, int b = N) { @@ -42,7 +42,7 @@ void update_tree(int idx, int val, int node = 1, int a = 0, int b = N) { tree[node] = tree[node * 2] + tree[node * 2 + 1]; } -// Return sum from i to j +// Return sum of [i,j] int query_tree(int i, int j, int node = 1, int a = 0, int b = N) { if (a > b || a > j || b < i) return 0; -- GitLab