Two-dimensional and two-dimensional differential prefix and

Recommended template title: [USACO19FEB] Painting at The Barn

Differential prefix and are inverse operations, i.e., the prefix differential arrays and arrays of the original array, the prefix differential arrays and arrays of the original array. Use of both inclusion and exclusion, this two-dimensional plane (or a two-dimensional array ) more pronounced embodied.

So we first prefix and in terms of two-dimensional

And two-dimensional prefix

Prefix and one-dimensional array is required from the first item of the array and to the current item, namely:
\ [SUM [I] = \ sum_ ^ {J} = {I}. 1 A [J] = (\ {J sum_ = 1} ^ {i-1
} a [j]) + a [i] = [i-1] + a [i] sum \] this is a prefix and dimensional recursive method.
then prefix and a two-dimensional we defined as the first line of a two-dimensional array of the first column (that is, the upper left corner) elements for the upper-left corner, and the current position of the element as an element matrix of the lower right corner. when we pushed \ ((i, j) \ ) when, we consider how to calculate \ ([i] SUM [J] \) . Since the upper left corner has been fixed, we consider only the lower right corner. when the lower-right corner for the \ ((i, j-1 ) \) when it is a \ ((i, j) \) matrix on the left side, when the lower right corner for the \ ((i-1, j ) \) , this indicates a \ ((i, j) \) matrix above. so if we ask \ ((i, j) \ ) at the top left of all elements and is not as long as the two already-calculated matrix and add up, plus \ (a [i] [j ] \) on the line it?

of course not.

Because the left upper matrix and the matrix has a overlapping portion, i.e. to a \ ((i-1, j -1) \) as the lower right corner, located entirely \ ((i, j) \ ) in the upper left matrix when directly adding it was counted twice, i.e., we want to subtract it:.
\ [SUM [I] [J] = \ sum_ ^ {P} = {I}. 1 \ sum_. 1} = {Q ^ {j} a [i] [j] = \ sum_ {p = 1} ^ {i} \ sum_ {q = 1} ^ {j-1} a [p] [q] + \ sum_ {p = 1 } ^ {i-1} \ sum_ {q = 1} ^ {j} a [p] [q] - \ sum_ {p = 1} ^ {i-1} \ sum_ {q = 1} ^ {j- 1} a [p] [q ] + a [i] [j] = sum [i] [j-1] + sum [i-1] [j] -sum [i-1] [j-1] + a [i] [j] \ ]

What this is two-dimensional and prefixes, find a matrix and when the process is similar.

Two-dimensional differential

Refers to a dimensional difference of each of how much more than the previous one, namely:
\ [CF2 [I] = A [I] -a [-I. 1] \]
can be implemented quickly by the differential section array and Fenwick tree subtraction, i.e. that the \ (CF2 [L] + V, CF2 [R & lt + 1] -v \) (note \ (R & lt \) to \ (1 + \) ). when we return to normal requirements form an array when, and if you ask prefix on it, namely:
\ [a [i] = cf \ _sum appended to [i-1] + cf [i] \]
? Well it is simply a two-dimensional differential does in the one-dimensional differential it also added a dimension which is a recurrence formula:.
\ [CF2 [I] [J] = a [I] [J] -a [I] [J-. 1] -a [-I. 1] [j] + a [i-
1] [j-1] \] i.e. the current element by subtracting the upper left element element plus minus left corner elements.

Then a two-dimensional array of difference requires the original number, and only requires a two-dimensional prefix can. May be quickly achieved through a two-dimensional matrix plus or minus differential.

Guess you like

Origin www.cnblogs.com/i-cookie/p/11517651.html