Codeforces Round 996 (Div. 2)
F
Cosmic Divide
Codeforces
3200
原题
← E→
翻译中…

With the artifact in hand, the fabric of reality gives way to its true master — Florida Man.

翻译中…

A polyomino is a connected$^{\text{∗}}$ figure constructed by joining one or more equal $1 \times 1$ unit squares edge to edge. A polyomino is convex if, for any two squares in the polyomino that share the same row or the same column, all squares between them are also part of the polyomino. Below are four polyominoes, only the first and second of which are convex.

翻译中…

image

翻译中…

You are given a convex polyomino with $n$ rows and an even area. For each row $i$ from $1$ to $n$, the unit squares from column $l_i$ to column $r_i$ are part of the polyomino. In other words, there are $r_i - l_i + 1$ unit squares that are part of the polyomino in the $i$-th row: $(i, l_i), (i, l_i + 1), \ldots, (i, r_i-1), (i, r_i)$.

翻译中…

Two polyominoes are congruent if and only if you can make them fit exactly on top of each other by translating the polyominoes. Note that you are not allowed to rotate or reflect the polyominoes. Determine whether it is possible to partition the given convex polyomino into two disjoint connected polyominoes that are congruent to each other. The following examples illustrate a valid partition of each of the two convex polyominoes shown above:

翻译中…

image

翻译中…

The partitioned polyominoes do not need to be convex, and each unit square should belong to exactly one of the two partitioned polyominoes.

翻译中…

$^{\text{∗}}$A polyomino is connected if and only if for every two unit squares $u \neq v$ that are part of the polyomino, there exists a sequence of distinct squares $s_1, s_2, \ldots, s_k$, such that $s_1 = u$, $s_k = v$, $s_i$ are all part of the polyomino, and $s_i, s_{i+1}$ share an edge for each $1 \le i \le k - 1$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the number of rows of the polyomino.

翻译中…

The $i$-th of the next $n$ lines contains two integers $l_i$ and $r_i$ ($1\le l_i\le r_i\le 10^9$) — the range of columns that are part of the polyomino in the $i$-th row.

翻译中…

It is guaranteed that the area of the polyomino is even. In other words, $\sum_{i=1}^n r_i - l_i + 1\equiv 0\pmod{2}$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, print a single line containing either "YES" or "NO", representing whether or not the polyomino can be partitioned as described in the problem.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

The first and second test cases are the polyominoes depicted in the problem statement and can be partitioned as shown.

翻译中…

The polyomino in the third test case, shown below, can be shown to be impossible to partition. None of the following partitions are valid:

翻译中…

image

翻译中…

The partition on the left does not use polyominoes that are translations of each other, and the partition on the right does not use connected polyominoes.

翻译中…

The polyomino in the fourth test case, shown below, can be shown to be impossible to partition.

翻译中…

image

翻译中…

Note that while you can partition it into two $1 \times 2$ rectangles, these rectangles are not translations of each other.

翻译中…

样例

Input #1
7
2
1 2
2 3
4
4 4
2 4
1 4
1 2
3
1 2
1 2
2 3
2
1 3
3 3
2
1 3
2 2
3
1 2
1 3
1 3
4
8 9
6 8
6 8
5 6
Output #1
YES
YES
NO
NO
NO
NO
YES
InputCopy OutputCopy
题目信息
题号
2055F
时间限制
4 s
内存限制
256 MB
标签
暴力
计算几何
哈希
数学
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。