Skip to content

Instantly share code, notes, and snippets.

@brpapa
Last active December 30, 2019 04:31
Show Gist options
  • Save brpapa/895b5bddefa3ef543761fe8d1993471d to your computer and use it in GitHub Desktop.
Save brpapa/895b5bddefa3ef543761fe8d1993471d to your computer and use it in GitHub Desktop.
segment tree
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