QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 1024 MB 總分: 100

#3873. 塔

统计

Benson the Rabbit 喜欢塔。共有 $N$ 座城市,编号为 $1$ 到 $N$,城市 $i$ 位于坐标为 $(X_i, Y_i)$ 的点上。没有两座城市位于同一个点。Benson 想要在其中一些城市建造塔,使得满足以下条件:

  • 对于任意 $a$,横坐标为 $a$ 的塔最多有两座。
  • 对于任意 $b$,纵坐标为 $b$ 的塔最多有两座。
  • 对于 $N$ 座城市中的每一座,要么在该城市建造了塔,要么该城市位于两座具有相同横坐标或相同纵坐标的塔之间的线段上。更正式地说,对于位于 $(x, y)$ 的城市,如果该城市没有塔,则存在两座坐标分别为 $(x, c)$ 和 $(x, d)$ 的塔,满足 $c \le y \le d$,或者存在两座坐标分别为 $(e, y)$ 和 $(f, y)$ 的塔,满足 $e \le x \le f$。

Benson 知道一定存在满足这些条件的建塔方案,但他不知道该如何建造。请帮助 Benson 确定他应该在哪些城市建造塔。

输入格式

程序必须从标准输入读取数据。

第一行包含一个整数 $N$,表示城市数量。

接下来的 $N$ 行中,第 $i$ 行包含两个整数 $X_i, Y_i$,表示城市 $i$ 位于点 $(X_i, Y_i)$。

输出格式

程序必须输出到标准输出。

输出一行,包含一个长度为 $N$ 的字符串 $A_1 A_2 \dots A_N$。如果 Benson 应该在城市 $i$ 建造塔,则 $A_i$ 应为 $1$,否则为 $0$。建造的塔必须满足所有条件。

如果存在多种方案,输出其中任意一种即可。

子任务

每个实例的最大执行时间为 2.0 秒。对于所有测试用例,输入满足以下范围:

  • $1 \le N \le 10^6$
  • $1 \le X_i, Y_i \le 10^6$
  • 对于所有 $i \neq j$,满足 $X_i \neq X_j$ 或 $Y_i \neq Y_j$。

你的程序将在满足以下限制的输入实例上进行测试:

子任务 分数 附加限制
1 5 $N \le 3$
2 11 $N \le 16$
3 7 $N = ab$,且对于所有 $0 \le i \le b-1, 1 \le j \le a$,满足 $(X_{ai+j}, Y_{ai+j}) = (i+1, j)$
4 6 对于每个整数 $a$,横坐标为 $a$ 的城市最多有两个
5 31 $N \le 5000$
6 21 $N \le 100000$
7 19 -

样例

样例输入 1

3
1 1
1 6
1 5

样例输出 1

110

说明 1

如果我们选择在城市 1 和 2 建造塔,它们具有相同的横坐标,而同样具有该横坐标的城市 3 位于它们之间的线段上。

一个错误的输出示例是 111,因为如果在这 3 座城市都建造塔,横坐标为 1 的塔将超过两座。

另一个错误的输出是 101,因为尽管城市 2 与城市 1 和 3 共享相同的纵坐标,但它并不位于它们之间的线段上。

样例输入 2

6
1 1
1 2
2 1
2 2
3 1
3 2

样例输出 2

110011

说明 2

城市 3 位于纵坐标相同的城市 1 和 5 之间的线段上,城市 4 位于纵坐标相同的城市 2 和 6 之间的线段上。

样例输入 3

8
1 13
2 13
7 27
7 13
7 2
2 27
7 4
4 13

样例输出 3

10101101

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.