309837: CF1742G. Orray

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:2 Solved:0

Description

Orray

题意翻译

给定一个数列 $a$,要求对 $a$ 重排,使得重排后 $a$ 的前缀或和数组 $b$ 字典序最大。 这里前缀或和的定义是:$b_i = a_1 \operatorname{or} a_2 \operatorname{or} \dots \operatorname{or} a_i$,其中 $\operatorname{or}$ 表示二进制按位或操作。 $t$ 组数据,保证 $1 \leq t \leq 100$,$1 \leq \sum n \leq 2 \times 10^5$,$0 \leq a_i \leq 10^9$。 By 一扶苏一

题目描述

You are given an array $ a $ consisting of $ n $ nonnegative integers. Let's define the prefix OR array $ b $ as the array $ b_i = a_1~\mathsf{OR}~a_2~\mathsf{OR}~\dots~\mathsf{OR}~a_i $ , where $ \mathsf{OR} $ represents the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). In other words, the array $ b $ is formed by computing the $ \mathsf{OR} $ of every prefix of $ a $ . You are asked to rearrange the elements of the array $ a $ in such a way that its prefix OR array is lexicographically maximum. An array $ x $ is lexicographically greater than an array $ y $ if in the first position where $ x $ and $ y $ differ, $ x_i > y_i $ .

输入输出格式

输入格式


The first line of the input contains a single integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $ n $ ( $ 1 \leq n \leq 2 \cdot 10^5 $ ) — the length of the array $ a $ . The second line of each test case contains $ n $ nonnegative integers $ a_1, \ldots, a_n $ ( $ 0 \leq a_i \leq 10^9 $ ). It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .

输出格式


For each test case print $ n $ integers — any rearrangement of the array $ a $ that obtains the lexicographically maximum prefix OR array.

输入输出样例

输入样例 #1

5
4
1 2 4 8
7
5 1 2 3 4 5 5
2
1 101
6
2 3 4 2 3 4
8
1 4 2 3 4 5 7 1

输出样例 #1

8 4 2 1 
5 2 1 3 4 5 5 
101 1 
4 3 2 2 3 4 
7 1 4 2 3 4 5 1

Input

题意翻译

给定一个数列 $a$,要求对 $a$ 重排,使得重排后 $a$ 的前缀或和数组 $b$ 字典序最大。 这里前缀或和的定义是:$b_i = a_1 \operatorname{or} a_2 \operatorname{or} \dots \operatorname{or} a_i$,其中 $\operatorname{or}$ 表示二进制按位或操作。 $t$ 组数据,保证 $1 \leq t \leq 100$,$1 \leq \sum n \leq 2 \times 10^5$,$0 \leq a_i \leq 10^9$。 By 一扶苏一

Output

**题意翻译**

给定一个数列 $a$,要求对 $a$ 重排,使得重排后 $a$ 的前缀或和数组 $b$ 字典序最大。

这里前缀或和的定义是:$b_i = a_1 \operatorname{or} a_2 \operatorname{or} \dots \operatorname{or} a_i$,其中 $\operatorname{or}$ 表示二进制按位或操作。

$t$ 组数据,保证 $1 \leq t \leq 100$,$1 \leq \sum n \leq 2 \times 10^5$,$0 \leq a_i \leq 10^9$。

**题目描述**

给定一个由 $ n $ 个非负整数组成的数组 $ a $。

定义前缀 OR 数组 $ b $ 为数组 $ b_i = a_1~\mathsf{OR}~a_2~\mathsf{OR}~\dots~\mathsf{OR}~a_i $,其中 $ \mathsf{OR} $ 表示按位或操作。换句话说,数组 $ b $ 是通过计算数组 $ a $ 的每个前缀的 $ \mathsf{OR} $ 值形成的。

要求重新排列数组 $ a $ 的元素,使得它的前缀 OR 数组字典序最大。

如果一个数组 $ x $ 在第一个与数组 $ y $ 不同的位置上的值 $ x_i $ 大于 $ y_i $,那么数组 $ x $ 字典序大于数组 $ y $。

**输入输出格式**

**输入格式**

输入的第一行包含一个整数 $ t $($ 1 \le t \le 100 $)——测试用例的数量。接下来是每个测试用例的描述。

每个测试用例的第一行包含一个整数 $ n $($ 1 \leq n \leq 2 \cdot 10^5 $)——数组 $ a $ 的长度。

每个测试用例的第二行包含 $ n $ 个非负整数 $ a_1, \ldots, a_n $($ 0 \leq a_i \leq 10^9 $)。

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

**输出格式**

对于每个测试用例,输出 $ n $ 个整数——任何能够获得字典序最大的前缀 OR 数组的数组 $ a $ 的重排。

**输入输出样例**

**输入样例 #1**

```
5
4
1 2 4 8
7
5 1 2 3 4 5 5
2
1 101
6
2 3 4 2 3 4
8
1 4 2 3 4 5 7 1
```

**输出样例 #1**

```
8 4 2 1
5 2 1 3 4 5 5
101 1
4 3 2 2 3 4
7 1 4 2 3 4 5 1
```**题意翻译** 给定一个数列 $a$,要求对 $a$ 重排,使得重排后 $a$ 的前缀或和数组 $b$ 字典序最大。 这里前缀或和的定义是:$b_i = a_1 \operatorname{or} a_2 \operatorname{or} \dots \operatorname{or} a_i$,其中 $\operatorname{or}$ 表示二进制按位或操作。 $t$ 组数据,保证 $1 \leq t \leq 100$,$1 \leq \sum n \leq 2 \times 10^5$,$0 \leq a_i \leq 10^9$。 **题目描述** 给定一个由 $ n $ 个非负整数组成的数组 $ a $。 定义前缀 OR 数组 $ b $ 为数组 $ b_i = a_1~\mathsf{OR}~a_2~\mathsf{OR}~\dots~\mathsf{OR}~a_i $,其中 $ \mathsf{OR} $ 表示按位或操作。换句话说,数组 $ b $ 是通过计算数组 $ a $ 的每个前缀的 $ \mathsf{OR} $ 值形成的。 要求重新排列数组 $ a $ 的元素,使得它的前缀 OR 数组字典序最大。 如果一个数组 $ x $ 在第一个与数组 $ y $ 不同的位置上的值 $ x_i $ 大于 $ y_i $,那么数组 $ x $ 字典序大于数组 $ y $。 **输入输出格式** **输入格式** 输入的第一行包含一个整数 $ t $($ 1 \le t \le 100 $)——测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含一个整数 $ n $($ 1 \leq n \leq 2 \cdot 10^5 $)——数组 $ a $ 的长度。 每个测试用例的第二行包含 $ n $ 个非负整数 $ a_1, \ldots, a_n $($ 0 \leq a_i \leq 10^9 $)。 保证所有测试用例的 $ n $ 之和不超过 $ 2 \cdot 10^5 $。 **输出格式** 对于每个测试用例,输出 $ n $ 个整数——任何能够获得字典序最大的前缀 OR 数组的数组 $ a $ 的重排。 **输入输出样例** **输入样例 #1** ``` 5 4 1 2 4 8 7 5 1 2 3 4 5 5 2 1 101 6 2 3 4 2 3 4 8 1 4 2 3 4 5 7 1 ``` **输出样例 #1** ``` 8 4 2 1 5 2 1 3 4 5 5 101 1 4 3 2 2 3 4 7 1 4 2 3 4 5 1 ```

加入题单

算法标签: