#P9298. [POI 2020/2021 R1] Tablica binarna / 01 矩阵

[POI 2020/2021 R1] Tablica binarna / 01 矩阵

Background

This problem is translated from XXVIII Olimpiada Informatyczna – Stage I Tablica binarna.

Problem Description

Matrix AA has nn rows and mm columns. Rows are numbered from 11 to nn from top to bottom, and columns are numbered from 11 to mm from left to right. Therefore, (i,j)(i, j) denotes the element in row ii and column jj of the matrix. Each element of matrix AA is either 00 or 11.

Initially, all elements in the matrix are 00. Then you can perform qq modification operations on this matrix. Each operation gives four parameters i1,j1,i2,j2i_1, j_1, i_2, j_2, meaning that you flip the value of every element inside the rectangle with top-left corner (i1,j1)(i_1, j_1) and bottom-right corner (i2,j2)(i_2, j_2) (changing 00 to 11, or 11 to 00).

If in an operation, the top-left corner of the rectangle coincides with the top-left corner of the matrix (i.e., i1=j1=1i_1 = j_1 = 1), then this modification operation is called simple.

Now you want to know, after each modification operation on the matrix, what is the minimum number of simple modification operations needed to make all elements in the matrix equal to 00.

Input Format

The first line contains three integers n,m,qn, m, q, representing the number of rows, the number of columns, and the number of operations.

The next qq lines each contain four integers i1,j1,i2,j2i_1, j_1, i_2, j_2, describing one modification operation. It is guaranteed that 1i1i2n1 \leq i_1 \leq i_2 \leq n and 1j1j2m1 \leq j_1 \leq j_2 \leq m.

Output Format

Output qq lines. The ii-th line should contain one integer, indicating that after the ii-th modification, what is the minimum number of simple modification operations needed to make all elements in the matrix equal to 00.

2 3 3
1 2 2 2
1 1 2 1
1 2 1 3
2
1
3
4 4 16
1 1 1 1
1 2 1 2
1 3 1 3
1 4 1 4
2 1 2 1
2 2 2 2
2 3 2 3
2 4 2 4
3 1 3 1
3 2 3 2
3 3 3 3
3 4 3 4
4 1 4 1
4 2 4 2
4 3 4 3
4 4 4 4
1
1
1
1
3
3
3
1
3
3
3
1
3
3
3
1

Hint

[Sample Explanation 1]:

[Constraints]:

All testdata satisfy: 1n,m1031 \leq n, m \leq 10^3, 1q1051 \leq q \leq 10^5.

Subtask ID Constraints Points
11 n,m2n, m \leq 2 1414
22 q=1q = 1 1616
33 n=1n = 1 2121
44 n,m10n, m \leq 10 99
55 n,m80n, m \leq 80 1010
66 No additional constraints 3030

Translated by ChatGPT 5