QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#11374. 整数生成器

الإحصائيات

给定一个整数集合 $S$,你的任务是使用不超过 70 次位运算来生成一个给定的整数 $x$。

具体来说,给定一个大小为 $n$ 的整数集合 $S$ 和一个整数 $x$,每次操作允许你从 $S$ 中选择两个整数 $a$ 和 $b$(它们可以是同一个),并将 $a \text{ or } b$、$a \oplus b$ 或 $a \text{ and } b$ 中的一个整数插入到 $S$ 中。你需要确定是否可以在不超过 70 次操作内使得 $x \in S$,如果可以,请提供一个有效的操作序列。

在此, $a \text{ or } b$ 指 $a$ 与 $b$ 的按位或,$a \oplus b$ 指 $a$ 与 $b$ 的按位异或,$a \text{ and } b$ 指 $a$ 与 $b$ 的按位与。

输入格式

第一行包含两个整数 $n, x$ ($1 \le n \le 10^5, 0 \le x < 2^{30}$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i < 2^{30}$),表示 $S$ 中的初始元素,保证这些整数互不相同。

输出格式

如果无法在不超过 70 次操作内使得 $x \in S$,输出一个整数 $-1$。

否则,第一行输出一个整数 $k$ ($0 \le k \le 70$),表示操作次数。

接下来输出 $k$ 行,每行表示一次操作。对于每次操作,输出三个整数 $t, a, b$ ($t \in \{0, 1, 2\}$)。如果 $t = 0$,表示该操作将 $a \text{ or } b$ 插入到 $S$ 中;如果 $t = 1$,表示该操作将 $a \oplus b$ 插入到 $S$ 中;如果 $t = 2$,表示该操作将 $a \text{ and } b$ 插入到 $S$ 中。你需要确保在执行该操作前,$S$ 中已经存在 $a$ 和 $b$。

在本题中,你不需要最小化操作次数;如果存在多个有效的操作序列,输出其中任意一个即可。

样例

样例输入 1

3 7
1 2 4

样例输出 1

2
1 1 2
1 3 4

样例输入 2

3 15
9 10 4

样例输出 2

2
0 10 9
1 4 11

样例输入 3

3 7
1 2 3

样例输出 3

-1

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.