#P6432. Overlapping Rectangles Color Area

    ID: 19646 Type: Default 1000ms 256MiB

Overlapping Rectangles Color Area

Overlapping Rectangles Color Area

We are given a white sheet of paper with width \(a\) and length \(b\) and \(n\) opaque rectangles with distinct colors. The sides of every rectangle are parallel to the edges of the paper, and each rectangle lies completely inside the paper. The rectangles are placed one after another in the given order. When a new rectangle is placed, it completely covers the region it occupies, hiding any color beneath it.

After all rectangles have been placed, every point on the paper shows either the white background (denoted by color 0) or one of the rectangle colors (denoted by 1 through \(n\), where rectangle \(i\) has color \(i\)). Your task is to compute the total visible area of each color.

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

The area calculations may be conveniently done using coordinate compression. For a given rectangle with bottom-left \((x_1,y_1)\) and top-right \((x_2,y_2)\), assume it covers the half-open region \([x_1,x_2)\times[y_1,y_2)\). In the final output, only colors with a positive area should be printed, sorted in ascending order by the color number (with 0 representing white).

inputFormat

The first line contains three integers \(n\), \(a\), and \(b\): the number of rectangles and the width and length of the white paper.

Each of the next \(n\) lines contains four integers \(x_1\), \(y_1\), \(x_2\), \(y_2\) representing the bottom-left and top-right coordinates of a rectangle. It is guaranteed that \(x_1 < x_2\) and \(y_1 < y_2\) and that each rectangle lies completely within the paper. The order in which rectangles are given is the order in which they are placed, with later rectangles covering earlier ones.

outputFormat

For each color that is visible (i.e. has a non-zero area), output a line in the format "color area", where the color is 0 for the white background or \(i\) (\(1 \le i \le n\)) for the \(i\)-th rectangle. The output should list the colors in increasing order (starting from 0).

sample

1 5 5
1 1 4 4
0 16

1 9

</p>