CF2261B.What's the Capital of France?

普及-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Obesity might not know the capital of France, but he does know that France has lots of restaurants.

There are nn restaurants in a line. The ii-th restaurant has rating aia_i.

Obesity can alter the ratings of the restaurants with his special power. In one operation, Obesity chooses two adjacent restaurants. If they have the same rating, nothing happens. Otherwise, the rating of the lower side is increased by 11.

Formally, in one operation, he does the following:

  • Choose an index ii (1≤i<n1 \le i \lt n).
  • If ai<ai+1a_i \lt a_{i+1}, increase aia_i by 11.
  • If ai=ai+1a_i = a_{i+1}, do nothing.
  • If ai>ai+1a_i \gt a_{i+1}, increase ai+1a_{i+1} by 11.

The delicacy of the restaurants is the value of the bitwise OR of the ratings of all restaurants.

What is the maximum delicacy Obesity can achieve after performing zero or more operations?

肥胖或许不知道法国的首都,但他确实知道法国有很多餐厅。

有 nn 家餐厅排成一行。第 ii 家餐厅的评分为 aia_i。

肥胖可以运用他的特殊能力修改餐厅的评分。在一次操作中,肥胖选择两家相邻的餐厅:若它们评分相同,则不发生任何变化;否则,将评分较低一侧的评分增加 11。

形式化地,在一次操作中,他执行以下步骤:

  • 选择一个下标 ii(满足 1≤i<n1 \le i < n);
  • 若 ai<ai+1a_i < a_{i+1},则将 aia_i 增加 11;
  • 若 ai=ai+1a_i = a_{i+1},则不进行任何操作;
  • 若 ai>ai+1a_i > a_{i+1},则将 ai+1a_{i+1} 增加 11。

餐厅的“精致度”定义为所有餐厅评分的按位或结果。

在执行零次或多次上述操作后,肥胖所能达到的最大精致度是多少?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The description of the test cases follows. The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是测试用例的描述。

测试用例的描述如下:每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \le a_i \le 10^9)。

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

输出格式

For each test case, print one integer — the maximum delicacy of all restaurants.

对于每个测试用例,输出一个整数——所有餐厅的最大精致度。

输入输出样例

  • 输入#1

    4
    1
    0
    2
    1 2
    2
    4 6
    3
    8 8 8

    输出#1

    0
    3
    7
    8

说明/提示

In the first test case, Obesity cannot perform any operations.

In the second test case, it is optimal for Obesity to perform no operations: 1 ∣ 2=31\, |\, 2 = 3.

In the third test case, Obesity can choose i=1i=1. Since 4≤64 \le 6, he increases the rating of the first restaurant by 11. The ratings are now [5,6][5,6], which gives a delicacy of 77. It can be shown that 77 is the maximum delicacy no matter how many operations are performed.

在第一个测试用例中,Obesity 无法执行任何操作。

在第二个测试用例中,Obesity 不执行任何操作是最优策略:1 ∣ 2=31\, |\, 2 = 3。

在第三个测试用例中,Obesity 可以选择 i=1i=1。由于 4≤64 \le 6,他将第一家餐厅的评分增加 11。此时评分为 [5,6][5,6],对应的美味度为 77。可以证明,无论执行多少次操作,77 都是所能达到的最大美味度。

输入解题思路,AI测评打分。不知道怎么写?

首页