This file contains 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
// [ql .. qr]: intervalo de consulta | |
int rangeQuery(int v, int l, int r, int ql, int qr) { | |
// v: índice atual da bt | |
// [l .. r]: intervalo atual de arr | |
if (ql > r || qr < l) | |
// [l .. r] está completamente fora de [ql .. qr] | |
return INF; | |
if (l >= ql && r <= ql) |
This file contains 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; | |
} |
This file contains 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 |