Skip to content

Commit 77762ab

Browse files
authored
Fix "build" function in segment_tree.md
Ensure that each node stores the maximum of its children. Otherwise the results of any query will be wrong, unless this node has been visited by an "update" query previously.
1 parent 4ba637e commit 77762ab

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/data_structures/segment_tree.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ void build(int a[], int v, int tl, int tr) {
694694
int tm = (tl + tr) / 2;
695695
build(a, v*2, tl, tm);
696696
build(a, v*2+1, tm+1, tr);
697-
t[v] = 0;
697+
t[v] = max(t[v*2], t[v*2 + 1]);
698698
}
699699
}
700700

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy