算法 - 插入排序交换次数 - Binary Indexed Tree
作者:互联网
- 场景:快速得到一段数组元素的和
- 题目:Insertion Sort Advanced Analysis | HackerRank
- 算法:binary-indexed-tree :: HackerRank
- 实现:binary-indexed-tree :: HackerRank 已经给出基本的实现了
// 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);
}
}
标签:Binary,val,HackerRank,binary,int,res,插入排序,Tree,indexed 来源: https://www.cnblogs.com/jffun-blog/p/12046221.html