Lecographically Maximum

시간 제한1초메모리 제한1024 MB

요약
N개의 정수에서 임의의 두 위치의 k번째 비트를 맞바꿀 수 있을 때, 도달 가능한 배열 중 사전순으로 최대인 배열을 구한다.
난이도

보통10점 중 7점

유형
비트 연산, 그리디, 정렬, 수학
정답자
아직 제출이 없습니다

문제

A list of NN integers a_1,…,a_Na\_1, \dots , a\_N is stored in the memory of an electronic device. This device has a very peculiar operation available: bit swapping between numbers. More precisely, given integers ii, jj and kk, this operation swaps the kk-th bit of the integer a_ia\_i with the kk-th bit of the integer a_ja\_j (and vice-versa).

Very interesting phenomena can occur when performing this operation one or more times, such as obtaining numbers that did not even belong to the original list, or even numbers larger or smaller than all the original elements.

For this problem, we are interested in using the operation as many times as necessary to change the list of numbers so that the resulting list is the lexicographically maximum, that is, that a_1a\_1 is the largest possible, that a_2a\_2 is the largest possible among the possible solutions that maximize a_1a\_1, and so on.

입력

The first line of input contains an integer NN (1≤N≤1051 ≤ N ≤ 10^5) and the second line contains NN integers, separated by spaces, corresponding to the list a_1,…,a_Na\_1, \dots , a\_N (0≤a_i≤1090 ≤ a\_i ≤ 10^9).

출력

Your program should print a single line containing NN space-separated integers corresponding to the lexicographically maximum obtainable sequence.

예제2

  1. 예제 1

    입력
    4
    8 4 2 1
    
    예상 출력
    15 0 0 0
    
  2. 예제 2

    입력
    4
    12 15 1 20
    
    예상 출력
    31 13 4 0