#P3260. [JLOI2014] 镜面通道

[JLOI2014] 镜面通道

Description

On a 2D plane, there is a mirror channel formed by mirrors ACAC and BDBD. The lengths of ACAC and BDBD are equal, and both are parallel to the xx-axis. BB is at (0, 0).

Inside the channel, there are nn optical elements whose outer surfaces are mirrors. Element α\alpha is a circle, and element β\beta is a rectangle (these elements may intersect with other elements and with the channel; see the figures). A light ray can enter the channel from any point on ABAB at any angle, and the light ray does not attenuate. If an element just touches another element, or an element just touches the channel boundary, the light is considered unable to pass through at that contact (for example, two tangent circles).

All information about the elements in the channel is given (α\alpha elements include the center coordinates and radius xi,yi,rix_i, y_i, r_i; β\beta elements include the lower-left and upper-right corner coordinates x1,y1,x2,y2x_1, y_1, x_2, y_2).

As shown in the first figure, SS to TT is a valid path.

Of course, there are cases where the light cannot pass through. Your task is to find the minimum number of optical elements that must be removed so that there exists a light path that can exit from CDCD.

An example is shown below: if the middle rectangle is removed, a light path passing through the channel can be constructed, as shown by SS to TT.

Input Format

  • The first line contains two integers, x,yx, y, denoting the coordinates of point CC.
  • The second line contains an integer nn, the number of optical elements.
  • Each of the next nn lines begins with a number. If it is 11, it denotes an α\alpha element, followed by three integers xi,yi,rix_i, y_i, r_i for the circle’s center and radius. If it is 22, it denotes a β\beta element, followed by four integers x1,y1,x2,y2x_1, y_1, x_2, y_2 for the rectangle’s lower-left and upper-right corner coordinates (rectangles are axis-aligned).

Output Format

Output one line containing a single integer mm, the minimum number of optical elements that need to be removed.

1000 100
6
1 500 0 50
2 10 10 20 100
2 100 10 200 100
2 300 10 400 100
2 500 10 600 100
2 700 0 800 100
2

Hint

Constraints: x105x \leq 10^5, y1000y \leq 1000, n300n \leq 300.

Translated by ChatGPT 5