Last active
December 30, 2019 04:31
-
-
Save brpapa/895b5bddefa3ef543761fe8d1993471d to your computer and use it in GitHub Desktop.
segment tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void buildBT(int v, int l, int r) { | |
// v: índice atual da bt | |
// [l .. r]: intervalo atual de arr | |
if (l == r) { | |
bt[v] = arr[l]; return; | |
} | |
int mid = (l + r) / 2; | |
buildBT(2*v+1, l, mid); // filho à esq de v | |
buildBT(2*v+2, mid+1, r); // filho à dir de v | |
bt[v] = min(bt[2*v+1], bt[2*v+2]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment