QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#17278. Point Elimination

統計

题目描述

在无限大的二维坐标平面上有 $N$ ($2 \leq N \leq 10^5, N$ 为偶数) 个点 $(x_i, y_i)$ ($1 \leq x_i, y_i \leq 10^6$)。

你可以执行以下两种操作任意多次:

  • 选择两个曼哈顿距离为 $1$ 的相邻点,并将这两个点移除。
  • 选择任意两个点,交换它们的 $y$ 坐标。形式化地,点 $(a, b)$ 和 $(c, d)$ 变为 $(a, d)$ 和 $(c, b)$。

请判断是否可以将平面上的所有点全部消除。注意,两个点可能会重合在同一个坐标上;它们仍被视为不同的点。你不能直接删除位于同一坐标的点,因为它们在技术上并不直接相邻。

输入格式

第一行包含一个整数 $T$ ($1 \leq T \leq 5000$),表示测试用例的数量。

每个测试用例的第一行包含一个整数 $N$。

接下来的 $N$ 行包含两个整数 $x_i$ 和 $y_i$。

保证所有测试用例的 $N$ 之和不超过 $5 \cdot 10^5$。

输出格式

对于每个测试用例,输出 "YES" 或 "NO"。

样例

输入 1

4
2
1 1
1 1
4
6 10
7 11
8 1
8 1
6
1 2
1 3
1 4
1 5
10 10
11 10
6
1 1
1 1
1 1
1 1
10 10
11 11

输出 1

NO
YES
YES
NO

说明 1

对于第一个测试用例,仅有的两个点坐标相同,因此任何交换操作都无效。所以答案为 NO。

在第二个测试用例中,我们可以交换 $(6, 10)$ 和 $(7, 11)$ 的 $y$ 坐标与 $(8, 1)$ 和 $(8, 1)$ 的 $y$ 坐标。然后,我们可以移除前两个点(水平相邻)和后两个点(垂直相邻)。

对于第三个测试用例,不需要进行交换。我们可以直接移除第一对、第二对和第三对。

在最后一个测试用例中,可以证明无论如何交换 $y$ 坐标,都无法将所有点以相邻对的形式移除。

子任务

  • 输入 2: $T \leq 1000, N \leq 6$
  • 输入 3-5: $N \leq 100$
  • 输入 6-11: 无额外限制。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.