#P9365. [ICPC2022 Xi'an R] Power of Two

[ICPC2022 Xi'an R] Power of Two

题目描述

$$2 ^ {2 ^ {2 ^ {2 ^ {2 ^ {2 ^ {2 ^ {2 ^ {2 ^ {2}}}}}}}}} $$

SolarPea likes blowing up PolarSea's blog by sending power tower of 22. As the tower is too high, the stack of the web page overflows. So the blog no longer works.

Now SolarPea has nn powers of two a1,a2,,ana_1, a_2, \ldots, a_n, xx bitwise AND operators, yy bitwise OR operators and zz bitwise XOR operators. It is guaranteed that n=x+y+zn = x + y + z.

Solarpea wants to construct an arithmetic expression with these numbers and operators. Formally, define x0=0x_0 = 0 and xi=xi1 opi bix_i = x_{i - 1}\ \mathrm{op}_i\ b_i, where bb is a permutation of aa, which means we can rearrange aa to get bb, and opi\mathrm{op}_i is one of the three types of bitwise operators above. Then xnx_n is the result of the expresstion.

The larger the expression, the more likely it is to make PolarSea's blog unable to work. SolarPea wants you to help him to find the largest xnx_n and construct such an expression. If there are multiple solutions, output any of them.

You need to process TT test cases independently.

输入格式

The first line contains a single integer TT (1T1051\leq T \leq 10 ^ 5), denoting the number of test cases.

For each test case, the first line contains four integers nn, xx, yy and zz (0x,y,zn65536,n=x+y+z0\leq x, y, z\leq n \leq 65\,536, n = x + y + z). The next line contains nn integers c1,c2,,cnc_1, c_2, \ldots, c_n (0ci<n0\leq c_i < n), where ai=2cia_i = 2 ^ {c_i}.

It is guaranteed that the sum of nn over all test cases is no more than 10485761\,048\,576.

输出格式

For each test case, output three lines.

The first line contains a 0101-string of length nn, representing the binary form of the largest xnx_n.

The next line contains a single 11-indexed string op\mathrm{op} of length nn, where opi\mathrm{op}_i represents the ii-th operator. Here, we denote AND as & (ASCII 38), OR as | (ASCII 124), and XOR as ^ (ASCII 94). You should guarantee that there is exactly xx AND operators, yy OR operators and zz XOR operators.

The third line contains nn integers d1,d2,,dnd_1, d_2, \ldots, d_n, the ii-th of which representing the logarithm of bib_i with base 22. That is, dd is a permutaion of cc.

If there are multiple solutions, output any of them.

4
4 3 0 1
1 0 1 0
4 1 0 3
1 0 1 0
8 0 2 6
1 5 5 7 1 5 5 7
8 0 0 8
1 5 5 7 1 5 5 7

0010
&&^&
0 0 1 1
0011
^^&^
0 1 0 1
10100000
^^|^^^^|
1 5 5 7 1 5 5 7
00000000
^^^^^^^^
1 5 5 7 1 5 5 7

提示

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem H.

Author: Alex_Wei.