A8378 | Compatible Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Two integers $x$ and $y$ are compatible, if the result of their bitwise "AND" equals zero, that is, $a$ $&$ $b=0$ . For example, numbers $90$ $(1011010_{2})$ and $36$ $(100100_{2})$ are compatible, as $1011010_{2}$ $&$ $100100_{2}=0_{2}$ , and numbers $3$ $(11_{2})$ and $6$ $(110_{2})$ are not compatible, as $11_{2}$ $&$ $110_{2}=10_{2}$ .
You are given an array of integers $a_{1},a_{2},...,a_{n}$ . Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.
You are given an array of integers $a_{1},a_{2},...,a_{n}$ . Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.
输入格式
The first line contains an integer $n$ ( $1<=n<=10^{6}$ ) — the number of elements in the given array. The second line contains $n$ space-separated integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=4·10^{6}$ ) — the elements of the given array. The numbers in the array can coincide.
输出格式
Print $n$ integers $ans_{i}$ . If $a_{i}$ isn't compatible with any other element of the given array $a_{1},a_{2},...,a_{n}$ , then $ans_{i}$ should be equal to -1. Otherwise $ans_{i}$ is any such number, that $a_{i}$ $&$ $ans_{i}=0$ , and also $ans_{i}$ occurs in the array $a_{1},a_{2},...,a_{n}$ .
输入输出样例
输入 #1
2 90 36
输出 #1
36 90
输入 #2
4 3 6 3 6
输出 #2
-1 -1 -1 -1
输入 #3
5 10 6 9 8 2
输出 #3
-1 8 2 2 8
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted