QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15717. 宝石建筑

Statistiques

你正在玩一个奇幻游戏,游戏开始时你有一排 $n$ 个能量水晶。第 $i$ 个水晶的能量等级为 $a_i$。

你可以进行以下操作任意次数:

  • 选择一组连续的相同水晶,即选择 $l$ 和 $r$($1 \le l \le r \le |a|$)使得 $a_l = a_{l+1} = \dots = a_r$;
  • 将它们融合为一个单一的水晶,其能量变为 $r - l + 1$,从而获得新的序列 $[a_1, \dots, a_{l-1}, r - l + 1, a_{r+1}, \dots, a_{|a|}]$。

注意,你也可以选择 $l = r$。

你想制作一个特定的水晶配置,其能量等级依次为 $b_1, \dots, b_m$。请判断这是否可行。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 500$)。接下来是每个测试用例的描述。

每个测试用例的第一行包含两个整数 $n, m$($1 \le m \le n \le 4000$)—— 分别表示初始配置和目标配置中的水晶数量。

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \le a_i \le 10^9$)—— 初始水晶的能量等级。

每个测试用例的第三行包含 $m$ 个整数 $b_1, b_2, \dots, b_m$($1 \le b_i \le 10^9$)—— 目标水晶的期望能量等级。

保证所有测试用例中 $n$ 的总和不超过 4000。

输出格式

对于每个测试用例,如果可以将初始配置转换为目标配置,则输出 YES,否则输出 NO

评测机不区分大小写(例如,YESYesyesyEs 都会被识别为肯定的回答)。

样例

输入样例 1

3
5 1
2 4 4 2 3
2
5 2
2 4 4 2 3
4 4
1 1
2
1

输出样例 1

YES
NO
YES

说明

样例 1 解释:在第一个测试用例中:

  • 初始配置为 $[2, 4, 4, 2, 3]$;
  • 融合子数组 $[l, r] = [2, 3]$ 中的两个水晶后,配置变为 $[2, 2, 2, 3]$;
  • 融合子数组 $[l, r] = [1, 3]$ 中的水晶后,配置变为 $[3, 3]$;
  • 融合子数组 $[l, r] = [1, 2]$ 中的水晶后,配置变为 $[2] = [b_1]$。因此答案为 YES

在第二个测试用例中,无法从 $[2, 4, 4, 2, 3]$ 出发获得 $[4, 4]$,因此答案为 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.