#P8216. [THUPC 2022 初赛] 画图

[THUPC 2022 初赛] 画图

Problem Description

The biannual THUPC is coming again. Xiao C and Xiao Z, as veteran contestants who have participated many times, naturally want to join in the fun as well. But since they are already “elderly,” competing is out of the question. They have also grown tired of the THUPC logo that has not changed for years, so to better attract everyone to sign up, they plan to redraw it into something flashier.

Seriously, how could you expect two nerdy programmer guys to have any artistic sense at all?

They knew this was beyond their abilities, so they decided to write an “artificial idiot” to help them draw the logo.

After unremitting effort, their artificial idiot finally runs. But they soon发现 it has even less artistic sense than they do—it can only draw horizontal and vertical line segments on the plane to assemble the word “THUPC”!

However, since the program is already written, it would be a waste not to use it. After studying this behavior, Xiao C and Xiao Z set the following rules:

For each horizontal segment, let its xx-coordinate interval be [li,ri][l_i, r_i] and its yy-coordinate be yiy_i; for each vertical segment, let its yy-coordinate interval be [di,ui][d_i, u_i] and its xx-coordinate be xix_i. All the above values are integers and satisfy ri>li,ui>dir_i > l_i, u_i > d_i.

The word “THUPC” should be formed by 1515 segments, numbered 1151 \thicksim 15. For each letter, the rules are:

The letter "T" consists of horizontal segment 11 and vertical segment 22, satisfying d2<y1=u2,l1<x2<r1d_2 < y_1 = u_2, l_1 < x_2 < r_1.

The letter "H" consists of vertical segment 33, horizontal segment 44, and vertical segment 55, satisfying d3=d5<y4<u3=u5,x3=l4<r4=x5d_3 = d_5 < y_4 < u_3 = u_5, x_3 = l_4 < r_4 = x_5.

The letter "U" consists of vertical segment 66, horizontal segment 77, and vertical segment 88, satisfying d6=d8=y7<u6=u8,x6=l7<r7=x8d_6 = d_8 = y_7 < u_6 = u_8, x_6 = l_7 < r_7 = x_8.

The letter "P" consists of vertical segment 99, horizontal segment 1010, horizontal segment 1111, and vertical segment 1212, satisfying $d_9 < y_{11} = d_{12} < u_9 = y_{10} = u_{12}, x_9 = l_{10} = l_{11} < r_{10} = r_{11} = x_{12}$.

The letter "C" consists of vertical segment 1313, horizontal segment 1414, and horizontal segment 1515, satisfying $d_{13} = y_{15} < u_{13} = y_{14}, x_{13} = l_{14} = l_{15} < r_{14} = r_{15}$.

These 55 letters may be placed anywhere on the plane and do not need to be arranged from left to right, but any two segments belonging to any two different letters must not intersect.

Note that the order of the segments output by the artificial idiot may not follow the numbering above. Also, segments in the same direction may be connected end-to-end, overlap, or contain one another; in such cases, they should be regarded as one continuous whole segment.

Only if, after merging and reordering, the generated segments satisfy the specifications above, is the logo considered correct. Otherwise, if there are extra segments, missing segments, coordinates that do not meet the requirements, etc., it is considered incorrect.

Finally, Xiao C and Xiao Z want to write a program to check whether each output of the artificial idiot satisfies the specifications. But after staying up late and grinding for three straight days, they are too exhausted to get up, so they ask you to help.

Input Format

Line 11: a positive integer nn indicating the number of segments, with 1n1051 \leq n \leq 10^5.

In the next nn lines, each line first contains an integer opiop_i, which is always 00 or 11:

  • If opi=0op_i = 0, the ii-th segment is a horizontal segment, followed by 33 integers li,ri,yil_i, r_i, y_i describing it, with li<ril_i < r_i.
  • If opi=1op_i = 1, the ii-th segment is a vertical segment, followed by 33 integers di,ui,xid_i, u_i, x_i describing it, with di<uid_i < u_i.

All input coordinates are guaranteed to be within [109,109][-10^9, 10^9].

Output Format

If it meets the specification, output the string Yes; otherwise, output the string No.

17
1 0 5 2
0 0 3 5
0 3 4 5
1 2 7 7
1 2 7 10
0 7 10 4
0 11 13 1
1 1 7 11
1 1 7 13
1 0 6 15
0 15 16 5
0 15 16 6
1 5 6 16
1 3 6 18
1 4 7 18
0 18 21 3
0 18 21 7
Yes

Hint

[Sample Explanation]

In this sample, the horizontal segment of the letter T and the vertical segment of the letter C are each formed by combining two segments.

Translated by ChatGPT 5