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

            while (right > 0)
            {
                sum  += tree[right];
                right = right - BitManipulation.GetFirstBit(right);
            }
            return(sum);
        }