#P5869. [SEERC 2018] Matrix Queries
[SEERC 2018] Matrix Queries
Description
Given a matrix, initially every cell is white. Each cell can be either white or black. Define the value of a matrix as follows:
- If the matrix is monochromatic, then its value is coin.
- Otherwise, split the matrix into equal-sized submatrices. The value of the matrix is the sum of the values of the submatrices plus coin.
You are given queries. Each query provides a row/column index . You need to flip the color of every cell in that row/column (black becomes white, white becomes black), and then compute the value of the new matrix after the change.
Input Format
The first line contains two integers and , meaning the matrix size is and there are queries.
The next lines each contain two integers and . If , flip the colors of row ; otherwise, flip the colors of column .
Output Format
For each query, output one line with the answer.
2 7
1 3
0 2
1 1
1 4
0 4
0 3
1 1
13
17
21
17
21
17
13
Hint
In the sample, the matrix after each query is shown in the figure below:

Translated by ChatGPT 5
京公网安备 11011102002149号