#P7783. 「MCOI-Zero / AC6-M14」Gracemeria Patrol
「MCOI-Zero / AC6-M14」Gracemeria Patrol
Description
You are given an 01 matrix. In each operation, you can flip the value at one position and the values directly above, left, and right of it. If the original value is , it becomes after flipping; otherwise it becomes .
For example, the matrix below becomes the following after flipping the position marked by brackets:
$$\begin{bmatrix}0&1&0&1&1\\1&0&[0]&1&0\\0&0&0&0&1\end{bmatrix}\rightarrow \begin{bmatrix}0&1&1&1&1\\1&1&1&0&0\\0&0&0&0&1\end{bmatrix}$$In particular, if the operation position is on the boundary, only the part that does not go out of bounds will be flipped.
Now you are given queries. Each query provides an interval and a constant . For the 01 submatrix consisting of rows with indices in , consider all ways to make it all by choosing some positions to perform exactly one operation on each chosen position. In those ways, output how many times row is operated on.
In particular, if there is no way, or there are multiple ways to choose operation positions, output .
Queries are independent of each other.
Input Format
The first line contains three integers .
The next lines each contain characters, describing the 01 matrix.
The next lines each contain three integers , describing a query.
Output Format
Output lines. Each line contains one integer, the answer to the corresponding query.
10 4 2
1010
0110
0101
0000
1011
0111
1110
1011
0001
1100
1 10 6
2 5 3
2
2
Hint
- Subtask 1 (10 pts): .
- Subtask 2 (20 pts): .
- Subtask 3 (20 pts): .
- Subtask 4 (20 pts): .
- Subtask 5 (30 pts): No special constraints.
For of the testdata, , , , .
idea: Sol1, solution: Sol1 & ethan_zhou, code: Sol1, data: Sol1
"Talisman..."
"An angel won't give up its wings unless
it has finished the last dance, right?"
Translated by ChatGPT 5
京公网安备 11011102002149号