A12798 | Bits And Pieces
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a$ of $n$ integers.
You need to find the maximum value of $a_{i} | ( a_{j} \& a_{k} )$ over all triplets $(i,j,k)$ such that $i < j < k$ .
Here $\&$ denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and $|$ denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
You need to find the maximum value of $a_{i} | ( a_{j} \& a_{k} )$ over all triplets $(i,j,k)$ such that $i < j < k$ .
Here $\&$ denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and $|$ denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
输入格式
The first line of input contains the integer $n$ ( $3 \le n \le 10^{6}$ ), the size of the array $a$ .
Next line contains $n$ space separated integers $a_1$ , $a_2$ , ..., $a_n$ ( $0 \le a_{i} \le 2 \cdot 10^{6}$ ), representing the elements of the array $a$ .
Next line contains $n$ space separated integers $a_1$ , $a_2$ , ..., $a_n$ ( $0 \le a_{i} \le 2 \cdot 10^{6}$ ), representing the elements of the array $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. $(1, 2, 3)$ , value of which is $2|(8\&4) = 2$ .
2. $(1, 2, 4)$ , value of which is $2|(8\&7) = 2$ .
3. $(1, 3, 4)$ , value of which is $2|(4\&7) = 6$ .
4. $(2, 3, 4)$ , value of which is $8|(4\&7) = 12$ .
The maximum value hence is $12$ .
In the second example, there are $4$ possible triplets:
1. $(1, 2, 3)$ , value of which is $2|(8\&4) = 2$ .
2. $(1, 2, 4)$ , value of which is $2|(8\&7) = 2$ .
3. $(1, 3, 4)$ , value of which is $2|(4\&7) = 6$ .
4. $(2, 3, 4)$ , value of which is $8|(4\&7) = 12$ .
The maximum value hence is $12$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted