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 \(x_1, x_2, \dots x_k.\)

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, a \ne b\) and   \( a \in S, b \in S\). 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 \(\sum_{i=1}^{k} |f(c, x_i) - f(d, x_i)|\) is minimum possible.

Help RedDreamer to paint the set optimally!

Input format

  • The first line contains one integer \(t (1≤t≤1000)\) — the number of test cases. 
  • The first line of each test case contains two integers \(n\) and \( k (1 ≤ n ≤ 10^5 , 0 ≤ k ≤ 1000)\)
  • The second line of each test case contains k integers \(x_1, x_2, . . . , x_n (0 ≤ x_i ≤ n).\)

Note: The sum of \(n\) test cases does not exceed \(10^5 \).

Output format

  • For each test case print \(n\) integers, \(p_0, p_1, p_2, . . . , p_n\) (each \(p_i \) 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 \(\sum_{i=1}^{k} |f(c, x_i) - f(d, x_i)|\), 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.\)

\(\sum_{i=1}^{k} |f(c, x_i) - f(d, x_i)|  = |1 - 1| + |1 - 1| + |1 - 1| + |0 - 0| = 0.\) 

Editor Image

?