QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 100
统计

Bytelandian 政府颁布了《银行安全统一法》(简称 BSU 法)。该法律规范了银行和其他金融机构中 Wi-Fi 路由器的使用。

根据 BSU 法,银行内的所有 $n$ 台 Wi-Fi 路由器必须排成一条直线。假设第 $i$ 台路由器的工作频率为 $f_i$。定义两个相邻路由器之间的连接安全性为 $f_i \& f_{i+1}$,其中 $\&$ 表示按位与运算。

必须选择至少两台编号为 $1 \le i_1 < i_2 < \dots < i_k \le n$ 的路由器作为“活跃”路由器。所有其他路由器将保持非活跃状态,以便在活跃路由器损坏时进行替换。定义网络的安全性为所有相邻活跃路由器之间连接的安全性之和。换句话说,网络的安全性计算公式为: $$\sum_{j=1}^{k-1} f_{i_j} \& f_{i_{j+1}}$$

你是 Bytelandian 一家大型银行的员工。银行必须遵守 BSU 法。路由器已经排成一行,且其位置无法更改。现在,你需要选择一些路由器作为活跃路由器,以最大化网络的安全性。

输入格式

第一行包含一个整数 $n$,表示银行中 Wi-Fi 路由器的数量 ($2 \le n \le 10^6$)。 第二行包含 $n$ 个整数 $f_1, f_2, \dots, f_n$,其中 $f_i$ 是第 $i$ 台路由器的频率 ($0 \le f_i \le 10^{12}$)。

输出格式

输出网络可能的最大安全性。

样例

样例输入 1

5
1 2 3 1 3

样例输出 1

5

样例输入 2

4
1 2 4 0

样例输出 2

0

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.