P8216 [THUPC 2022 Preliminary] Drawing
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 $x$-coordinate interval be $[l_i, r_i]$ and its $y$-coordinate be $y_i$; for each vertical segment, let its $y$-coordinate interval be $[d_i, u_i]$ and its $x$-coordinate be $x_i$. All the above values are integers and satisfy $r_i > l_i, u_i > d_i$.
The word “THUPC” should be formed by $15$ segments, numbered $1 \thicksim 15$. For each letter, the rules are:
The letter "T" consists of horizontal segment $1$ and vertical segment $2$, satisfying $d_2 < y_1 = u_2, l_1 < x_2 < r_1$.
The letter "H" consists of vertical segment $3$, horizontal segment $4$, and vertical segment $5$, satisfying $d_3 = d_5 < y_4 < u_3 = u_5, x_3 = l_4 < r_4 = x_5$.
The letter "U" consists of vertical segment $6$, horizontal segment $7$, and vertical segment $8$, satisfying $d_6 = d_8 = y_7 < u_6 = u_8, x_6 = l_7 < r_7 = x_8$.
The letter "P" consists of vertical segment $9$, horizontal segment $10$, horizontal segment $11$, and vertical segment $12$, 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 $13$, horizontal segment $14$, and horizontal segment $15$, satisfying $d_{13} = y_{15} < u_{13} = y_{14}, x_{13} = l_{14} = l_{15} < r_{14} = r_{15}$.
These $5$ 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 $1$: a positive integer $n$ indicating the number of segments, with $1 \leq n \leq 10^5$.
In the next $n$ lines, each line first contains an integer $op_i$, which is always $0$ or $1$:
- If $op_i = 0$, the $i$-th segment is a horizontal segment, followed by $3$ integers $l_i, r_i, y_i$ describing it, with $l_i < r_i$.
- If $op_i = 1$, the $i$-th segment is a vertical segment, followed by $3$ integers $d_i, u_i, x_i$ describing it, with $d_i < u_i$.
All input coordinates are guaranteed to be within $[-10^9, 10^9]$.
Output Format
If it meets the specification, output the string `Yes`; otherwise, output the string `No`.
Explanation/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