Anti-Closed Subsequences

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

요약
서로 다른 n개의 정수를 60개 이하의 무리로 나누되 어느 무리에서도 x+y=z인 세 원소가 나타나지 않도록 하고, 각 위치의 무리 번호를 출력한다.
난이도

어려움10점 중 8점

유형
조합론, 그리디, 수학, 완전 탐색
정답자
아직 제출이 없습니다

문제

We consider a set of integers SS to be anti-closed if there do not exist elements xx, yy and zz in SS where x+y=zx+y=z (xx, yy and zz do not necessarily have to be distinct).

For example:

  • 2,3,7\\{2, 3, 7\\} is anti-closed, because no such xx, yy, zz exist
  • 1,3,7,10\\{1, 3, 7, 10\\} is not anti-closed, because 33, 77, and 1010 are all in the set and 3+7=103+7=10
  • 2,4\\{2, 4\\} is also not anti-closed, because 22 and 44 are in the set and 2+2=42+2=4

You are given an array aa of nn distinct integers. Partition it into at most 6060 anti-closed subsequences. Formally, find an array bb of size nn such that

  • 1≤b_i≤601 \leq b\_i \leq 60 for all 1≤i≤n1 \le i \le n
  • For each 1≤x≤601 \le x \le 60, the subsequence of aa containing all values at indices ii where b_i=xb\_i = x is anti-closed (The empty subsequence is considered anti-closed)

It can be shown that a solution always exists.

입력

The first line of the input contains a single integer nn (1≤n≤1041 \le n \le 10^4) --- the size of the array aa.

The next line of the input contains nn distinct integers a_1,a_2⋯a_na\_1, a\_2 \cdots a\_n (1≤a_i≤10181 \le a\_i \le 10^{18}) --- the elements of the array aa.

출력

Output nn integers b_1,b_2,⋯b_nb\_1, b\_2, \cdots b\_n (1≤b_i≤601 \le b\_i \le 60), representing the partition of aa, as described above.

If there are multiple solutions, print any.

힌트

For the first test case, the input array is partitioned into these subsequences:

  • b_i=1b\_i = 1: 1,4,6,15\\{1, 4, 6, 15\\}
  • b_i=2b\_i = 2: 2,3,9,10,14\\{2, 3, 9, 10, 14\\}
  • b_i=3b\_i = 3: 5,7,8\\{5, 7, 8\\}
  • b_i=4b\_i = 4: 11,12,13\\{11, 12, 13\\}

We can show that each of these sets is anti-closed.

예제2

  1. 예제 1

    입력
    15
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    
    예상 출력
    1 2 2 1 3 1 3 3 2 2 4 4 4 2 1
    
  2. 예제 2

    입력
    3
    250000000000000000 500000000000000000 1000000000000000000
    
    예상 출력
    1 2 3