Two sets

0

0 votes
C++, Basic Math, Bitmask, Math, Sets
Problem

You are given a set S consisting of n+1 non-negative integers, S=0,1,...,n. Also, you have k unlucky integers x1,x2,xk.

Let's denote the X- misfortune of the set S, f(S,X) --- the number of pairs of integers (a,b) such that a+b=X,ab and   aS,bS. RedDreamer has to paint each element of S into one of two colors, white and black, and then create two sets c and d so that all white elements belong to c, and all the black elements belong to d (it is possible that one of these two sets becomes empty). RedDreamer wants to paint the elements in such a way that ki=1|f(c,xi)f(d,xi)| is minimum possible.

Help RedDreamer to paint the set optimally!

Input format

  • The first line contains one integer t(1t1000) — the number of test cases. 
  • The first line of each test case contains two integers n and k(1n105,0k1000)
  • The second line of each test case contains k integers x1,x2,...,xn(0xin).

Note: The sum of n test cases does not exceed 105.

Output format

  • For each test case print n integers, p0,p1,p2,...,pn (each pi is either 0 or 1) denoting the colors. If i is 0, then i is white and belongs to the set c, otherwise, it is black and belongs to the set d
  • If there are multiple answers that minimize the value of ki=1|f(c,xi)f(d,xi)|, print any of them.
Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Let's look to the the 2-test case:

c=0,1,3,4,8;d=2,5,6,7,9,10.

f(c, 7) = 1 (4 and 3). f(d, 7) = 1(2 and 5).

f(c, 8) = 1 (0 and 8). f(d, 8) = 1(2 and 6).

f(c, 9) = 1 (1 and 8). f(d, 8) = 1(2 and 7).

f(c,10)=0;f(d,10)=0.

ki=1|f(c,xi)f(d,xi)|=|11|+|11|+|11|+|00|=0. 

Editor Image

?