Fenwick tree

Fenwick tree (aka Binary indexed tree) is a data structure that maintains a sequence of elements, and is able to compute cumulative sum of any range of consecutive elements in $$O(\log n)$$ time. Changing value of any single element needs $$O(\log n)$$ time as well.

The structure is space-efficient in the sense that it needs the same amount of storage as just a simple array of $$n$$ elements.