QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#4810. Add One

Statistics

给定 $n$ 个整数 $a_1, a_2, \dots, a_n$,你需要执行以下操作恰好 $n - 1$ 次:

  • 从序列中选择两个整数 $x$ 和 $y$,将它们移除,并加入一个值为 $x \oplus y$ 的数。

由于这太无聊了,你还可以在任意时刻选择一个数并将其加一。你必须执行加一操作恰好一次。

最终,序列中将只剩下一个数,你需要最大化这个剩余的数。输出该剩余数的最大值。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^6$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i < 2^{60}$)。

输出格式

输出一行,包含一个整数:剩余数的最大值。

样例

输入 1

4
1 2 1 2

输出 1

7

输入 2

5
1 2 3 4 5

输出 2

14

输入 3

6
1 2 4 7 15 31

输出 3

47

说明

在第一个样例中,最优策略为:

  • 选择 1 和 2:$[1, 2, 1, 2] \to [1, 2, 3]$
  • 选择 1 和 2:$[1, 2, 3] \to [3, 3]$
  • 将数字 3 加一:$[3, 3] \to [3, 4]$
  • 选择 3 和 4:$[3, 4] \to [7]$

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.