#P9583. 「MXOI Round 1」涂色
「MXOI Round 1」涂色
Problem Description
Xiao C is using colored pencils to color a grid paper with rows and columns. Initially, all cells are blank.
He will perform coloring operations in total. In each operation, he chooses either a row or a column, and adds layer of color to every cell in that row or column.
Xiao C likes light colors, so after each operation, he will erase the color of all cells that have been colored with exactly layers, making those cells blank again.
Xiao C wants to know how many cells are colored in the end.
Input Format
The first line contains four integers .
The next lines each contain two integers .
- If , it means adding layer of color to all cells in row ;
- If , it means adding layer of color to all cells in column .
Output Format
Output one integer, indicating how many cells are colored in the end.
3 4 5 3
1 3
2 4
1 2
1 3
2 2
8
Hint
[Sample Explanation #1]
The cell in row , column is not colored; the cell in row , column has layer of color; the cell in row , column is not colored; the cell in row , column has layer of color;
The cell in row , column has layer of color; the cell in row , column has layers of color; the cell in row , column has layer of color; the cell in row , column has layers of color;
The cell in row , column has layers of color; the color of the cell in row , column is erased; the cell in row , column has layers of color; the color of the cell in row , column is also erased;
In the end, a total of cells are colored.
[Sample #2]
See paint/paint2.in and paint/paint2.ans in the attached files.
This sample satisfies the constraints of test points .
[Sample #3]
See paint/paint3.in and paint/paint3.ans in the attached files.
This sample satisfies the constraints of test points .
[Sample #4]
See paint/paint4.in and paint/paint4.ans in the attached files.
This sample satisfies the constraints of test points .
[Constraints]
For of the data, , , . It is guaranteed that when , , and when , .
| Test point ID | Special property | ||
|---|---|---|---|
| None | |||
| A | |||
| B | |||
| None |
Special property A: It is guaranteed that .
Special property B: It is guaranteed that .
Translated by ChatGPT 5