QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#5120. 2 的幂

Statistics

SolarPea 喜欢通过发送 2 的幂塔来搞垮 PolarSea 的博客。由于塔太高了,网页的栈溢出了,导致博客无法正常工作。

现在 SolarPea 有 $n$ 个 2 的幂 $a_1, a_2, \dots, a_n$,$x$ 个按位与运算符,$y$ 个按位或运算符以及 $z$ 个按位异或运算符。保证 $n = x + y + z$。

SolarPea 想要用这些数字和运算符构造一个算术表达式。形式化地,定义 $x_0 = 0$ 且 $x_i = x_{i-1} \operatorname{op}_i b_i$,其中 $b$ 是 $a$ 的一个排列,这意味着我们可以重排 $a$ 得到 $b$,且 $\operatorname{op}_i$ 是上述三种按位运算符之一。$x_n$ 即为表达式的结果。

表达式的值越大,越有可能使 PolarSea 的博客无法工作。SolarPea 希望你帮他找到最大的 $x_n$ 并构造出这样一个表达式。如果存在多种方案,输出其中任意一种。

你需要独立处理 $T$ 组测试数据。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试数据组数。

对于每组测试数据,第一行包含四个整数 $n, x, y, z$ ($0 \le x, y, z \le n \le 65\,536, n = x+y+z$)。

下一行包含 $n$ 个整数 $c_1, c_2, \dots, c_n$ ($0 \le c_i < n$),其中 $a_i = 2^{c_i}$。

保证所有测试数据的 $n$ 之和不超过 $1\,048\,576$。

输出格式

对于每组测试数据,输出三行。

第一行包含一个长度为 $n$ 的 01 字符串,表示最大的 $x_n$ 的二进制形式。

第二行包含一个长度为 $n$ 的 1-indexed 字符串 $\operatorname{op}$,其中 $\operatorname{op}_i$ 表示第 $i$ 个运算符。这里,我们将 AND 表示为 & (ASCII 38),OR 表示为 | (ASCII 124),XOR 表示为 ^ (ASCII 94)。你需要保证恰好有 $x$ 个 AND 运算符,$y$ 个 OR 运算符和 $z$ 个 XOR 运算符。

第三行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$,其中第 $i$ 个数表示 $b_i$ 以 2 为底的对数。即,$d$ 是 $c$ 的一个排列。

如果存在多种方案,输出其中任意一种。

样例

输入 1

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

输出 1

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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.