CF1208F.Bits And Pieces
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of n integers.
You need to find the maximum value of ai∣(aj&ak) over all triplets (i,j,k) such that i<j<k.
Here & denotes the bitwise AND operation, and ∣ denotes the bitwise OR operation.
给你一个包含 n 个整数的数组 a。
你需要在所有满足 i<j<k 的三元组 (i,j,k) 中,找出表达式 ai∣(aj&ak) 的最大值。
输入格式
The first line of input contains the integer n (3≤n≤106), the size of the array a.
Next line contains n space separated integers a1, a2, ..., an (0≤ai≤2⋅106), representing the elements of the array a.
输入的第一行包含整数 n(3≤n≤106),表示数组 a 的大小。
第二行包含 n 个用空格分隔的整数 a1, a2, ..., an(0≤ai≤2⋅106),表示数组 a 的元素。
输出格式
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). Hence, the answer is 2∣(4&6)=6.
In the second example, there are 4 possible triplets:
- (1,2,3), value of which is 2∣(8&4)=2.
- (1,2,4), value of which is 2∣(8&7)=2.
- (1,3,4), value of which is 2∣(4&7)=6.
- (2,3,4), value of which is 8∣(4&7)=12.
The maximum value hence is 12.
在第一个例子中,唯一可能的三元组是 (1,2,3)。因此,答案为 2∣(4&6)=6。
在第二个例子中,共有 4 个可能的三元组:
- (1,2,3),其值为 2∣(8&4)=2。
- (1,2,4),其值为 2∣(8&7)=2。
- (1,3,4),其值为 2∣(4&7)=6。
- (2,3,4),其值为 8∣(4&7)=12。
因此,最大值为 12。
输入解题思路,AI测评打分。不知道怎么写?