#P2930. Holiday Painting Verification
Holiday Painting Verification
Holiday Painting Verification
The cows wish to create a festive painting on a grid. The painting is represented by an \(R \times C\) grid where each cell is colored either white (0) or black (1). The rows are numbered from 1 to \(R\) and the columns from 1 to \(C\).
Initially, the canvas is entirely painted white (0). A target picture is also provided as an \(R \times C\) grid (each cell is 0 or 1) which the cows wish to mimic.
A special paint machine is used to speed things up. It performs \(Q\) operations. Each operation is specified by five integers \(R1_i, R2_i, C1_i, C2_i, X_i\) (with \(1 \le R1_i \le R2_i \le R\), \(1 \le C1_i \le C2_i \le C\), and \(X_i \in \{0,1\}\)). This means that in every row from \(R1_i\) to \(R2_i\) (inclusive), the columns from \(C1_i\) to \(C2_i\) (inclusive) are painted with color \(X_i\).
After each operation, the cows wish to know how many cells of their current canvas match the target picture (i.e. are of the same color in the same position).
Note: In all descriptions, any formulae (such as \(R \times C\)) must be rendered using LaTeX format.
inputFormat
The first line contains three integers \(R\), \(C\), and \(Q\) \( (1 \le R \le 50000,\ 1 \le C \le 15,\ 1 \le Q \le 10000)\).
The next \(R\) lines each contain a string of length \(C\) consisting only of the characters '0' and '1'. This represents the target picture. The first character of the string corresponds to column 1, the second to column 2, and so on.
The following \(Q\) lines each contain five integers: \(R1\), \(R2\), \(C1\), \(C2\), \(X\) (with \(1 \le R1 \le R2 \le R\), \(1 \le C1 \le C2 \le C\), and \(X \in \{0,1\}\)), representing one paint operation.
outputFormat
Output \(Q\) lines. The \(i\)th line should contain a single integer representing the total number of cells that are painted correctly (i.e. match the target picture) after the \(i\)th operation.
sample
3 3 2
010
101
010
1 2 2 3 1
2 3 1 2 0
5
6
</p>