CF165E.Compatible Numbers

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002 = 02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102 = 102.

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.

两个整数 xx 和 yy 是相容的,当且仅当它们的按位“与”(bitwise AND)结果为零,即 x&y=0x \& y = 0。例如,数字 9090(二进制表示为 101101021011010_2)和 3636(二进制表示为 1001002100100_2)是相容的,因为 10110102&1001002=021011010_2 \& 100100_2 = 0_2;而数字 33(二进制表示为 11211_2)和 66(二进制表示为 1102110_2)不相容,因为 112&1102=10211_2 \& 110_2 = 10_2。

给定一个整数数组 a1, a2, …, ana_1,\, a_2,\, \dots,\, a_n。你的任务是对数组中的每个元素,回答如下问题:该元素是否与数组中某个其他元素相容?若答案为肯定,则还需找出任意一个满足条件的对应元素。

输入格式

The first line contains an integer n (1 ≤ n ≤ 106) — 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·106) — the elements of the given array. The numbers in the array can coincide.

第一行包含一个整数 nn(1≤n≤1061 \leq n \leq 10^6)—— 给定数组的元素个数。
第二行包含 nn 个以空格分隔的整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1≤ai≤4⋅1061 \leq a_i \leq 4\cdot10^6)—— 给定数组的元素。
数组中的数字可以重复。

输出格式

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.

输出 nn 个整数 ansians_i。若 aia_i 与给定数组 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n 中的任意其他元素都不兼容,则 ansians_i 应为 −1-1;否则 ansians_i 可取任意满足 ai&ansi=0a_i \& ans_i = 0 且 ansians_i 出现在数组 a1, a2, ..., ana_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

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

首页