P9298 [POI 2020/2021 R1] Tablica binarna / 01 Matrix
Background
**This problem is translated from [XXVIII Olimpiada Informatyczna – Stage I](https://sio2.mimuw.edu.pl/c/oi28-1/dashboard/) [Tablica binarna](https://sio2.mimuw.edu.pl/c/oi28-1/p/tab/).**
Description
Matrix $A$ has $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from top to bottom, and columns are numbered from $1$ to $m$ from left to right. Therefore, $(i, j)$ denotes the element in row $i$ and column $j$ of the matrix. Each element of matrix $A$ is either $0$ or $1$.
Initially, all elements in the matrix are $0$. Then you can perform $q$ modification operations on this matrix. Each operation gives four parameters $i_1, j_1, i_2, j_2$, meaning that you flip the value of every element inside the rectangle with top-left corner $(i_1, j_1)$ and bottom-right corner $(i_2, j_2)$ (changing $0$ to $1$, or $1$ to $0$).
If in an operation, the top-left corner of the rectangle coincides with the top-left corner of the matrix (i.e., $i_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 $0$.
Input Format
The first line contains three integers $n, m, q$, representing the number of rows, the number of columns, and the number of operations.
The next $q$ lines each contain four integers $i_1, j_1, i_2, j_2$, describing one modification operation. It is guaranteed that $1 \leq i_1 \leq i_2 \leq n$ and $1 \leq j_1 \leq j_2 \leq m$.
Output Format
Output $q$ lines. The $i$-th line should contain one integer, indicating that after the $i$-th modification, what is the minimum number of **simple** modification operations needed to make all elements in the matrix equal to $0$.
Explanation/Hint
[Sample Explanation 1]:

[Constraints]:
All testdata satisfy: $1 \leq n, m \leq 10^3$, $1 \leq q \leq 10^5$.
| Subtask ID | Constraints | Points |
| :----------: | :-------------: | :----: |
| $1$ | $n, m \leq 2$ | $14$ |
| $2$ | $q = 1$ | $16$ |
| $3$ | $n = 1$ | $21$ |
| $4$ | $n, m \leq 10$ | $9$ |
| $5$ | $n, m \leq 80$ | $10$ |
| $6$ | No additional constraints | $30$ |
Translated by ChatGPT 5