QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100

#1830. AND

統計

你曾经有一个数组 $a$。之后,你计算了原数组所有子数组的按位与(bitwise AND)。形式化地,你计算了所有形如 $a_i \text{ AND } a_{i+1} \text{ AND } \dots \text{ AND } a_j$ 的数,其中 $1 \le i \le j \le \text{length}(a)$。

你记得这些数构成的集合:一个数在这个集合中,当且仅当它能表示为至少一个子数组的按位与。遗憾的是,你忘记了原来的数组。

请找出一个能产生给定按位与集合的数组 $a$,或者确定不存在这样的数组。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^5$),表示测试用例的数量。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示给定集合的大小。

每个测试用例的第二行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($0 \le b_i \le 2^{20} - 1$),表示集合中的元素。保证所有元素互不相同。

保证所有测试用例中 $n$ 的总和不超过 $10^5$。

输出格式

对于每个测试用例,如果不存在这样的数组,输出 $-1$。

否则,在第一行输出原数组的大小 $k$ ($1 \le k \le 5n$)。

在下一行输出 $k$ 个整数 $a_1, a_2, \dots, a_k$ ($0 \le a_i \le 2^{20} - 1$),表示数组的元素。

如果有多个可能的答案,输出其中任意一个即可。

可以证明,如果存在至少一个满足条件的数组,则一定存在一个满足这些条件的数组。

样例

输入 1

3
1
5
3
0 1 2
2
1 2

输出 1

3
5 5 5
3
1 0 2
-1

说明

注意,你输出的数组中的元素不需要互不相同。

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.