QOJ.ac

QOJ

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

#1817. AND 排列

统计

给定一个包含 $n$ 个互不相同的非负整数的序列 $a_1, a_2, \dots, a_n$。

对于给定的序列,保证对于所有非负整数 $x$,如果存在某个 $i$ 使得 $a_i \ \& \ x = x$,则一定存在某个 $j$ 使得 $a_j = x$。其中,$\&$ 表示按位与运算符。

请找到 $a_1, a_2, \dots, a_n$ 的一个排列 $b_1, b_2, \dots, b_n$,使得对于所有 $i$,满足 $b_i \ \& \ a_i = 0$。如果存在多种解,输出其中任意一个即可。题目保证一定存在解。

输入

第一行包含一个整数 $n$ ($1 \le n < 2^{18}$),表示序列中整数的个数。

接下来的 $n$ 行,每行包含一个整数 $a_i$ ($0 \le a_i < 2^{60}$),按顺序给出输入序列。

保证所有的 $a_i$ 互不相同。对于所有非负整数 $x$,如果存在某个 $i$ 使得 $a_i \ \& \ x = x$,则一定存在某个 $j$ 使得 $a_j = x$。

输出

输出 $n$ 行,每行包含一个整数,依次为排列后的 $b_i$。

样例

输入格式 1

6
0
1
4
5
2
6

输出格式 1

4
6
0
2
5
1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#619Editorial Open集训队作业 解题报告 by 洪泽Qingyu2026-01-02 23:13:32 Download
#597Editorial Open集训队作业 解题报告 by 陈翔乐Qingyu2026-01-02 22:49:26 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.