#P6432. [USACO3.1] 形成的区域 Shaping Regions

[USACO3.1] 形成的区域 Shaping Regions

Description

nn opaque rectangles of different colors are placed on a sheet of white paper with width aa and height bb. Their edges are parallel to the edges of the paper, and all rectangles are placed inside the paper.

Now they are overlapped. After overlapping, various colored regions of different shapes will appear. You need to find the area of each color.

The coordinates of the lower-left corner of the paper are the origin (0,0)(0,0), and the coordinate axes are parallel to the edges of the paper.

Input Format

The input has a total of n+1n+1 lines.

The first line contains three integers a,b,na,b,n.

Lines 22 to n+1n+1 each contain five integers llx,lly,urx,ury,colorllx,lly,urx,ury,color, representing the coordinates of the lower-left corner and upper-right corner of a rectangle, and its color index. Note: Color 11 is the same as the color of the bottom white paper.

Output Format

Output a summary of every visible color and its total area. Each line should contain the color index and the area. Even if the regions of a color are not connected, you should still output the total area. Output the results in increasing order of colorcolor, and do not output colors with zero visible area.

20 20 3
2 2 18 18 2
0 8 19 19 3
8 0 10 19 4
1 91
2 84
3 187
4 38

Hint

Explanation for Sample Input/Output 1

After all layers have covered the paper, the areas of the colors are 91,84,187,3891,84,187,38, respectively.


Constraints

For 100%100\% of the testdata, 1n1031 \leq n \leq 10^3, 1a,b1041 \leq a,b \leq 10^4, 1llx,lly,urx,urya,b1 \leq llx,lly,urx,ury \leq a,b, 1colorn+11 \leq color \leq n+1.

Translated by ChatGPT 5