QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100

#10008. 这难道不美吗?

Statistics

我们定义一个数组的“美观度”为其最小排除值(MEX):即不属于该数组的最小非负整数。MEX 越大,数组越美观。

给定一个长度为 $n$ 的数组 $a$。你想要提升它的美观度。为此,你可以选择一个非负整数 $x$,并将每个元素 $a_i$ 替换为 $a_i \& x$。其中,$\&$ 表示按位与运算符:结果的每一位等于操作数对应位的逻辑与。

请找到一个能使数组美观度最大化的 $x$ 值。

输入格式

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

每个测试用例包含两行。 第一行包含一个整数 $n$ ($1 \le n \le 10^5$)。 第二行包含 $n$ 个整数 $a_1, \dots, a_n$ ($0 \le a_i < 2^{30}$)。

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

输出格式

对于每个测试用例,输出一个能使数组(由 $a$ 中每个元素与 $x$ 进行按位与运算得到)的 MEX 最大化的整数 $x$。该值应满足 $0 \le x < 2^{30}$;可以证明在该范围内总存在一个最优的 $x$。如果存在多个解,输出其中任意一个即可。

样例

输入 1

1
6
13 11 40 10 33 19

输出 1

23

说明

在样例中,我们可以选择 $x = 23$,那么新数组将变为 $[13\&23, 11\&23, 40\&23, 10\&23, 33\&23, 19\&23]$, 即 $[5, 3, 0, 2, 1, 19]$,其 MEX 为 $4$。另一个可能的答案是 $x = 19$。

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.