- Scene: quickly get some of the array elements and
- 题目:Insertion Sort Advanced Analysis | HackerRank
- 算法:binary-indexed-tree :: HackerRank
- Realization: binary-indexed-Tree :: HackerRank has been given a basic implementation
// get cumulative sum up to and including i
int Get(int i) {
int res = 0;
while(i) {
res += B[i];
i -= (i & -i);
}
return res;
}
// add val to value at i
void Set(int i, int val) {
while(i <= N) {
B[i] += val;
i += (i & -i);
}
}