CF1208F.Bits And Pieces

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa of nn integers.

You need to find the maximum value of ai(aj&ak)a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k)(i,j,k) such that i<j<ki < j < k .

Here &\& denotes the bitwise AND operation, and | denotes the bitwise OR operation.

输入格式

The first line of input contains the integer nn ( 3n1063 \le n \le 10^{6} ), the size of the array aa .

Next line contains nn space separated integers a1a_1 , a2a_2 , ..., ana_n ( 0ai21060 \le a_{i} \le 2 \cdot 10^{6} ), representing the elements of the array aa .

输出格式

Output a single integer, the maximum value of the expression given in the statement.

输入输出样例

  • 输入#1

    3
    2 4 6
    

    输出#1

    6
    
  • 输入#2

    4
    2 8 4 7
    

    输出#2

    12
    

说明/提示

In the first example, the only possible triplet is (1,2,3)(1, 2, 3) . Hence, the answer is 2(4&6)=62 | (4 \& 6) = 6 .

In the second example, there are 44 possible triplets:

  1. (1,2,3)(1, 2, 3) , value of which is 2(8&4)=22|(8\&4) = 2 .
  2. (1,2,4)(1, 2, 4) , value of which is 2(8&7)=22|(8\&7) = 2 .
  3. (1,3,4)(1, 3, 4) , value of which is 2(4&7)=62|(4\&7) = 6 .
  4. (2,3,4)(2, 3, 4) , value of which is 8(4&7)=128|(4\&7) = 12 .

The maximum value hence is 1212 .

首页