QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#17983. 合并时间线

统计

“谁控制了过去,谁就控制了未来。” —— 乔治·奥威尔,《1984》

由全宇宙智慧物种组成的 UCPC(宇宙一致性维护委员会)发现,宇宙已经分裂成了 $N$ 条时间线。时间线 $i$ 拥有一个整数时间值 $a_i$(满足 $1 \le a_i \le N$),且这些时间值两两不同。每条时间线目前都是稳定的,但随时可能变得不稳定,而一条不稳定的时间线可能会产生超出人类认知范围的不利影响。由于事关整个宇宙的存亡,后果极其严重,UCPC 得出结论:必须将这 $N$ 条时间线合并为一条时间值为 $t$ 的单条时间线。

合并时间线是指将两条相邻的时间线合并为一条,并取它们时间值的最大值或最小值作为新时间线的时间值。对于 $1 \le i < N$,时间线 $i$ 和 $i+1$ 被认为是相邻的。在宇宙尺度上,合并时间线是一个不可逆的过程,必须极其小心地进行。因此,分别取最小值和取最大值的合并次数是有限制的。在这些约束条件下,请判断 UCPC 是否能成功将所有时间线合并为一条。

输入格式

输入的第一行包含一个整数 $T$,表示测试用例的数量。($1 \le T \le 100\,000$)

每个测试用例的第一行包含四个整数 $N, t, a, b$,分别表示时间线的数量 $N$、目标时间值 $t$、取最小值合并的最大次数 $a$,以及取最大值合并的最大次数 $b$。($2 \le N \le 500\,000$;$1 \le t \le N$;$0 \le a, b < N$;$a + b \ge N - 1$)

每个测试用例的第二行包含 $N$ 个空格分隔的整数 $A_1, A_2, \cdots, A_N$。$A_i$ 表示第 $i$ 条时间线的时间值。每个 $A_i$ 都是介于 $1$ 和 $N$ 之间(含 $1$ 和 $N$)的整数,且两两不同。

所有测试用例的 $N$ 之和不超过 $500\,000$。

输出格式

按顺序输出每个测试用例的答案。

如果无法在给定条件下合并时间线,则在第一行输出 no

如果可以,则在第一行输出 yes;第二行输出一个长度为 $N - 1$ 且仅由 mM 组成的字符串 $S$;第三行输出 $N - 1$ 个空格分隔的整数 $b_i$。

其中 $S_i$ 为 m 表示第 $i$ 次合并取最小值,为 M 表示第 $i$ 次合并取最大值。$b_i$ 表示第 $i$ 次合并是在当时相邻的第 $b_i$ 条和第 $b_i + 1$ 条时间线之间进行的。如果存在多种满足条件的合并方案,输出其中任意一种即可。

注意,在进行第 $i$ 次合并之前,还剩下 $N - i + 1$ 条时间线,因此必须满足 $1 \le b_i \le N - i$。

样例

输入 1

2
4 2 2 3
1 4 2 3
3 3 2 0
3 1 2

输出 1

yes
mMm
2 1 1
no

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.