Last active
December 30, 2019 05:32
-
-
Save brpapa/47bf3d8516c7c563aef2c4266eb3378d 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
// value: novo valor de arr[i] | |
void pointUpdate(int v, int l, int r, int i, int value) { | |
// v: índice atual da bt | |
// [l .. r]: intervalo atual de arr | |
if (l == r) { | |
// v é nó folha | |
bt[v] = value; return; | |
} | |
int mid = (l+r)/2; | |
if (i <= mid) | |
pointUpdate(2*v+1, l, mid, i, value); | |
else | |
pointUpdate(2*v+2, mid+1, r, i, value); | |
// na volta, após ter atualizado o vértice folha | |
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