Basic algorithms - prefix and differential

I do not know why I'm not the most fundamental algorithms ...

definition

For one-dimensional, the prefix and a difference process is relatively simple.

And prefixes, that is a series of numbers, all the elements of the i-th element and its previous. For a number of columns in A, and S prefix information

difference. I.e., i-1 and the difference between items in item i. Given a number of column A, column B which is the difference in score

 It can be seen, the prefix and a pair of differential and reciprocal calculation.

Prefix and a sequence difference sequence B is the original sequence A

Difference sequence and a sequence S is the prefix of the original sequence A

The nature of the above is very important, it will be used in two-dimensional later.

application

Prefix and can quickly help us to obtain a certain range and.

I.e., for an interval (l, r) in the original sequence A, and the prefix sequence S

Difference can quickly help us at the same time interval plus, minus operation.

For the interval (l, r) of the original sequence A plus d is changed to its difference sequence

Bl+d ,Br+1-d

Other locations not need to change. If you need real equipment to the original sequence, just to make a difference sequence prefix and can be.

Two-dimensional

 Here to explain the reference to an example will appear more natural

Laser bomb BZOJ1218

Title to

Our S [i, j] represents the prefix and two-dimensional. So we are going to look at

S[i,j],S[i-1,j],S[i,j-1],S[i-1,j-1]

 

 So that we can get this recursive

 

Guess you like

Origin www.cnblogs.com/Uninstalllingyi/p/11413143.html