#P15058. [UOI 2023 II Stage] Rectangles are everywhere

    ID: 16989 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>并查集2023UOI(乌克兰)

[UOI 2023 II Stage] Rectangles are everywhere

Problem Description

Andriyko drank a lot of compote and now he's very afraid of rectangles. Andriyko's room can be mathematically represented as a rectangle with height nn and width mm. In this room, there are kk rectangles, each of which is completely inside the room and does not touch the points (0,0)(0,0) and (n,m)(n,m) (where (0,0)(0,0) is the top-left and (n,m)(n,m) is the bottom-right point).

Andriyko wants to go from the corner (0,0)(0,0) to (n,m)(n,m) without ever touching any of the kk rectangles (not even touching them). If he is at coordinate (x,y)(x,y), then he can move to any of the following coordinates with one step: (x0.5,y)(x-0.5,y), (x+0.5,y)(x+0.5,y), (x,y0.5)(x,y-0.5), (x,y+0.5)(x,y+0.5), but only if the next coordinate does not go beyond the boundaries of the rectangle.

Determine if he can reach from one corner to the other.

Input Format

The first line contains three integers nn, mm, kk (1n,m106,1k5000)(1 \le n,m \le 10^6, 1 \le k \le 5\,000).

Each of the next kk lines contains four integers x1x_1, y1y_1, x2x_2, y2y_2 (0x1x2n;0y1y2m)(0 \le x_1 \le x_2 \le n; 0 \le y_1 \le y_2 \le m) --- the coordinates of the top-left and bottom-right corners of rectangle ii.

It is guaranteed that no rectangle touches the points (0,0)(0,0) and (n,m)(n,m).

Output Format

Print YES\tt{YES} if Andriyko can travel between the ends of the room, and NO\tt{NO} otherwise.

3 4 3
0 2 1 4
1 2 3 3
2 1 3 3
NO
3 4 3
0 2 1 4
1 0 2 1
2 1 3 3
YES

Hint

  • (33 points): k=1k = 1
  • (44 points): k=2k = 2
  • (55 points): k=3k = 3
  • (1717 points): 1k501 \le k \le 50
  • (2626 points): 1k10001 \le k \le 1000
  • (2020 points): 1n,m50001 \le n,m \le 5000
  • (2525 points): no additional constraints.