Skip to content

Commit 1af10d5

Browse files
authored
Merge pull request #1213 from akoutian/patch-1
Add "build" function to segment_tree.md
2 parents 382f675 + 0a5336e commit 1af10d5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/data_structures/segment_tree.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,17 @@ Before traversing to a child vertex, we call $\text{push}$ and propagate the val
805805
We have to do this in both the $\text{update}$ function and the $\text{query}$ function.
806806

807807
```cpp
808+
void build(int a[], int v, int tl, int tr) {
809+
if (tl == tr) {
810+
t[v] = a[tl];
811+
} else {
812+
int tm = (tl + tr) / 2;
813+
build(a, v*2, tl, tm);
814+
build(a, v*2+1, tm+1, tr);
815+
t[v] = max(t[v*2], t[v*2 + 1]);
816+
}
817+
}
818+
808819
void push(int v) {
809820
t[v*2] += lazy[v];
810821
lazy[v*2] += lazy[v];

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