Created
February 7, 2013 03:47
-
-
Save rcabreu/4728270 to your computer and use it in GitHub Desktop.
C++::data_structures::BinaryIndexedTree
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
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