QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#11199. 姐妹城市

统计

经过多年的冷淡外交关系,拜托齐亚(Bajtocja)和比托齐亚(Bitocja)两国决定通过建立两国城市间的紧密关系来改善现状。

拜托齐亚有 $n$ 座城市,比托齐亚也有 $n$ 座城市。两国政府希望在它们之间建立友好城市关系,即为拜托齐亚的每一座城市指定唯一的一座比托齐亚友好城市,反之亦然:为比托齐亚的每一座城市指定唯一的一座拜托齐亚友好城市。

友好城市之间将频繁交换信息,因此这些城市的邮政编码必须匹配。拜托齐亚的每座城市都有一个唯一的整数邮政编码。比托齐亚的情况类似,但可能出现拜托齐亚的某座城市与比托齐亚的某座城市邮政编码相同的情况。民意调查专家预测,如果拜托齐亚邮政编码为 $a_i$ 的城市与比托齐亚邮政编码为 $b_j$ 的城市建立合作关系,将使两地居民的幸福感增加 $a_i \oplus b_j$。此处 $\oplus$ 表示异或运算(xor):$x \oplus y$ 的第 $i$ 位为 $1$ 当且仅当 $x$ 和 $y$ 的第 $i$ 位中恰好有一个为 $1$。

政府现在正在考虑如何进行配对。这并不容易,因为对于每一对选定的城市,至少要有一座城市感到“满意”,即对于该城市而言,选择其他任何城市作为合作伙伴都无法带来更高的幸福感。

请编写一个程序,判断是否存在满足居民要求的友好城市配对方案,如果存在,请输出任意一种配对方案。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 50\,000$),表示每个国家的城市数量。

第二行包含 $n$ 个不同的整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^{18}$),表示拜托齐亚各城市的邮政编码。

第三行包含 $n$ 个不同的整数 $b_1, b_2, \dots, b_n$ ($0 \le b_i \le 10^{18}$),表示比托齐亚各城市的邮政编码。

输出格式

如果无法按照要求分配友好城市,请输出一行 NIE

否则,第一行输出 TAK。接下来一行输出 $n$ 个整数:第 $i$ 个整数为 $m_i$,表示拜托齐亚编号为 $i$ 的城市应与比托齐亚编号为 $m_i$ 的城市建立合作关系。

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

样例

输入格式 1

3
2 5 4
3 5 1

输出格式 1

TAK
2 1 3

输入格式 2

3
2 5 1
3 5 1

输出格式 2

NIE

输入格式 3

2
1 1123438534808147
0 2462061299839

输出格式 3

TAK
2 1

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.