public void Modify(int index, int difference) { index += 1; // offset while (index < tree.Length) { tree[index] += difference; index += BitManipulation.GetFirstBit(index); } }
public int GetCumulative(int right) { right += 1; // offset int sum = 0; while (right > 0) { sum += tree[right]; right = right - BitManipulation.GetFirstBit(right); } return(sum); }