Fenwick tree maintenance intervals modify the query interval

For single-point range to modify the query, we can be marked by the use of a differential increase in the beginning and end of the array, the array using the tree to maintain its prefix and change can be derived for each position, namely:
\ [A_x = a_x + \ sum_ {i = 1} ^ xb_i
\] then for the interval may be modified by the query interval for each point within the interval to perform the above operation, i.e.:
\ [\ sum_ {L} = I ^ rA_i = \ sum_ {I = l} ^ r \ sum_ {j
= 1} ^ ib_j + \ sum_ {i = 1} ^ ra_i \] the question then is transformed to use Fenwick tree maintenance \ (\ sum_ {i = l } ^ r \ sum_ {j = } ^ ib_j. 1 \) .

We can simplify this problem for the sake \ (\ sum_ = {I}. 1 ^ rA_i- \ sum_ = {I}. 1. 1} ^ {L-A_i \) .

We only need to \ (\ sum_ = {I}. 1 xA_i ^ \) .

Significance difference by the formula can be simplified as:
\ [\ sum_. 1} ^ {X = I (I +. 1-X) \ Times B_i = (X +. 1) \ sum_ = {I}. 1 ^ xb_i- \ sum_ {i = 1} ^ xi
\ times b_i \] then the two prefixes and to maintain.

Guess you like

Origin www.cnblogs.com/MicDZ/p/Binary-Indexed-Trees.html