Skip to content

Instantly share code, notes, and snippets.

@rcabreu
Created February 7, 2013 03:47
Show Gist options
  • Save rcabreu/4728270 to your computer and use it in GitHub Desktop.
Save rcabreu/4728270 to your computer and use it in GitHub Desktop.
C++::data_structures::BinaryIndexedTree
int C[N];
int read(int i) {
int sum = 0;
while (i > 0) {
sum += C[i];
i -= (i & -i);
}
return sum;
}
void update(int i, int val) {
while (i < N) {
C[i] += val;
i += (i & -i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment