Skip to content

Instantly share code, notes, and snippets.

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