#P9478. [NOI2023] 方格染色
[NOI2023] 方格染色
Problem Description
There is a chessboard with columns and rows, with a total of cells. We agree that both rows and columns are numbered starting from , and the cell in column and row has coordinates . Initially, all cells are white. Now you need to perform coloring operations on this chessboard.
There are three types of coloring operations:
- Color a horizontal segment black. Specifically, given two cells and , with and , color all cells between these two cells (including them) black.
- Color a vertical segment black. Specifically, given two cells and , with and , color all cells between these two cells (including them) black.
- Color a diagonal segment black. Specifically, given two cells and , with and , color all cells on the diagonal between them of the form () black. The number of times this type of coloring operation occurs does not exceed .
Now you want to know: after the coloring operations, how many black cells are on the chessboard.
Input Format
The first line contains an integer , which indicates the test point index. means this test point is a sample.
The second line contains three positive integers , representing the number of columns, the number of rows, and the number of coloring operations.
The next lines each contain five positive integers . Here, means the first type of coloring operation, means the second type, and means the third type. are the four parameters of the coloring operation.
Output Format
Output one line containing an integer, representing the number of cells colored black on the chessboard.
0
5 5 3
1 1 3 5 3
2 3 1 3 5
3 1 1 5 5
13
见附件中的 color/color2.in。
见附件中的 color/color2.ans。
见附件中的 color/color3.in。
见附件中的 color/color3.ans。
见附件中的 color/color4.in。
见附件中的 color/color4.ans。
见附件中的 color/color5.in。
见附件中的 color/color5.ans。
见附件中的 color/color6.in。
见附件中的 color/color6.ans。
见附件中的 color/color7.in。
见附件中的 color/color7.ans。
Hint
[Sample Explanation #1]
In this sample, we performed a total of three coloring operations, as shown in the figure below.

In the first operation, we colored black.
In the second operation, we colored black.
In the third operation, we colored black.
[Sample #2]
This sample satisfies the constraints for test points .
[Sample #3]
This sample satisfies the constraints for test points .
[Sample #4]
This sample satisfies the constraints for test points .
[Sample #5]
This sample satisfies the constraints for test points .
[Sample #6]
This sample satisfies the constraints for test points .
[Sample #7]
This sample satisfies the constraints for test point .
[Constraints]
For all testdata, it is guaranteed that: , , , , and there are at most operations of the third type.
::cute-table{tuack}
| Test Point Index | Special Property | ||
|---|---|---|---|
| None | |||
| A | |||
| B | |||
| None | |||
Special property A: it is guaranteed that there are only the first type of coloring operations.
Special property B: it is guaranteed that there are only the first and second types of coloring operations.
Update on 2023-08-04: A set of Hack testdata was updated, where .
Translated by ChatGPT 5