Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Last active April 12, 2017 06:16
int sumRange(int i, int j) {
return sumQuery(i, j, 0, n - 1, 0);
}
int sumQuery(int qlo, int qhi, int clo, int chi, int i)
{
if(qlo > chi || qhi < clo)return 0;
if(qlo <= clo && qhi >= chi)return st[i].val;
int mid = clo + (chi - clo) / 2;
return sumQuery(qlo, qhi, clo, mid, 2 * i + 1) + sumQuery(qlo, qhi, mid + 1, chi, 2 * i + 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment