CF165E.Compatible Numbers

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Two integers xx and yy are compatible, if the result of their bitwise "AND" equals zero, that is, aa & b=0b=0 . For example, numbers 9090 (10110102)(1011010_{2}) and 3636 (1001002)(100100_{2}) are compatible, as 101101021011010_{2} & 1001002=02100100_{2}=0_{2} , and numbers 33 (112)(11_{2}) and 66 (1102)(110_{2}) are not compatible, as 11211_{2} & 1102=102110_{2}=10_{2} .

You are given an array of integers a1,a2,...,ana_{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 nn ( 1<=n<=1061<=n<=10^{6} ) — the number of elements in the given array. The second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=41061<=a_{i}<=4·10^{6} ) — the elements of the given array. The numbers in the array can coincide.

输出格式

Print nn integers ansians_{i} . If aia_{i} isn't compatible with any other element of the given array a1,a2,...,ana_{1},a_{2},...,a_{n} , then ansians_{i} should be equal to -1. Otherwise ansians_{i} is any such number, that aia_{i} & ansi=0ans_{i}=0 , and also ansians_{i} occurs in the array 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
首页