Fenwick tree base template

Fenwick tree is used to find the range, and a single point of support and modification of efficient data structures,
when talking about Fenwick tree often have such a picture:

looks very sick, and very difficult to understand (a little understanding of how to achieve but do not know) ...
However ta code is very short, at least as a board problem, ta very pattern is broken Tucson spicy ...
as we all know, the simple algorithm seeking prefix and ideas extremely simple, with code like this:

int sum[233];
int a[233];  //everything is '0'
...          //something like read
for(int i=1;i<=100;i++){
    sum[i]=sum[i-1]+a[i];
}

ps recently wrote notes in Chinese exploded (garbled), and then switch to a small article in English
is known from the above code, this simple algorithm is very violent, and does not support the modification operation, modification TLE,
now with an array of such a tree data structure, the specific elements grouped into a certain set, so that a single point can be modified only modify the node containing the element, a lot of high-efficiency
specifically how to achieve it?
Fenwick tree is based on binary "number the unique nature of decomposition "data structure,
the nature of the above is the binary number represented by each is different, to prove the correctness of their own
based on this property, a \ (1 ~ x \)

Guess you like

Origin www.cnblogs.com/648-233/p/11124408.html