CF1779D.Boris and His Amazing Haircut

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Boris thinks that chess is a tedious game. So he left his tournament early and went to a barber shop as his hair was a bit messy.

His current hair can be described by an array a1,a2,…,ana_1,a_2,\ldots, a_n, where aia_i is the height of the hair standing at position ii. His desired haircut can be described by an array b1,b2,…,bnb_1,b_2,\ldots, b_n in a similar fashion.

The barber has mm razors. Each has its own size and can be used at most once. In one operation, he chooses a razor and cuts a segment of Boris's hair. More formally, an operation is:

  • Choose any razor which hasn't been used before, let its size be xx;
  • Choose a segment [l,r][l,r] (1≤l≤r≤n1\leq l \leq r \leq n);
  • Set ai:=min⁡(ai,x)a_i := \min (a_i,x) for each l≤i≤rl\leq i \leq r;

Notice that some razors might have equal sizes — the barber can choose some size xx only as many times as the number of razors with size xx.

He may perform as many operations as he wants, as long as any razor is used at most once and ai=bia_i = b_i for each 1≤i≤n1 \leq i \leq n at the end. He does not have to use all razors.

Can you determine whether the barber can give Boris his desired haircut?

鲍里斯认为国际象棋是一项枯燥乏味的游戏,因此他提前离开了比赛,去了一家理发店——因为他的头发有点乱。

他当前的发型可用一个数组 a1,a2,…,ana_1,a_2,\ldots, a_n 描述,其中 aia_i 表示位置 ii 处头发的高度。他期望的发型则可用类似方式描述为数组 b1,b2,…,bnb_1,b_2,\ldots, b_n。

理发师有 mm 把剃刀,每把剃刀具有各自的尺寸,且最多只能使用一次。每次操作中,他选择一把剃刀并修剪鲍里斯头发的一段区域。更准确地说,一次操作定义如下:

  • 任选一把尚未使用过的剃刀,设其尺寸为 xx;
  • 任选一个区间 [l,r][l,r](满足 1≤l≤r≤n1\leq l \leq r \leq n);
  • 对每个满足 l≤i≤rl\leq i \leq r 的下标 ii,令 ai:=min⁡(ai,x)a_i := \min (a_i,x);

注意:某些剃刀可能具有相同的尺寸——理发师最多只能对尺寸 xx 执行与尺寸为 xx 的剃刀数量相等次数的操作。

他可以执行任意多次操作,只要满足:每把剃刀至多使用一次,且最终对所有 1≤i≤n1 \leq i \leq n 均有 ai=bia_i = b_i。他不必使用全部剃刀。

你能判断理发师是否能为鲍里斯理出他期望的发型吗?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤20 0001 \leq t \leq 20\,000). The description of the test cases follows.

The first line of each test case contains a positive integer nn (3≤n≤2⋅1053\leq n\leq 2\cdot 10^5) — the length of arrays aa and bb.

The second line of each test case contains nn positive integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — Boris's current hair.

The third line of each test case contains nn positive integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \leq b_i \leq 10^9) — Boris's desired hair.

The fourth line of each test case contains a positive integer mm (1≤m≤2⋅1051 \leq m \leq 2\cdot 10^5) — the number of razors.

The fifth line of each test case contains mm positive integers x1,x2,…,xmx_1,x_2, \ldots, x_m (1≤xi≤1091 \leq x_i \leq 10^9) — the sizes of the razors.

It is guaranteed that the sum of nn and the sum of mm over all test cases do not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤20 0001 \leq t \leq 20\,000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个正整数 nn(3≤n≤2⋅1053\leq n\leq 2\cdot 10^5)—— 数组 aa 和 bb 的长度。

每个测试用例的第二行包含 nn 个正整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— Boris 当前的发型。

每个测试用例的第三行包含 nn 个正整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \leq b_i \leq 10^9)—— Boris 理想的发型。

每个测试用例的第四行包含一个正整数 mm(1≤m≤2⋅1051 \leq m \leq 2\cdot 10^5)—— 剃刀的数量。

每个测试用例的第五行包含 mm 个正整数 x1,x2,…,xmx_1,x_2, \ldots, x_m(1≤xi≤1091 \leq x_i \leq 10^9)—— 剃刀的尺寸。

保证所有测试用例中 nn 的总和以及 mm 的总和均不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, print "YES" if the barber can cut Boris's hair as desired. Otherwise, print "NO".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

对于每个测试用例,如果理发师能够按照 Boris 的要求为其剪发,则输出 “YES”;否则输出 “NO”。

您可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。

输入输出样例

  • 输入#1

    7
    3
    3 3 3
    2 1 2
    2
    1 2
    6
    3 4 4 6 3 4
    3 1 2 3 2 3
    3
    3 2 3
    10
    1 2 3 4 5 6 7 8 9 10
    1 2 3 4 5 6 7 8 9 10
    10
    1 2 3 4 5 6 7 8 9 10
    3
    1 1 1
    1 1 2
    12
    4 2 4 3 1 5 6 3 5 6 2 1
    13
    7 9 4 5 3 3 3 6 8 10 3 2 5
    5 3 1 5 3 2 2 5 8 5 1 1 5
    8
    1 5 3 5 4 2 3 1
    13
    7 9 4 5 3 3 3 6 8 10 3 2 5
    5 3 1 5 3 2 2 5 8 5 1 1 5
    7
    1 5 3 4 2 3 1
    3
    19747843 2736467 938578397
    2039844 2039844 2039844
    1
    2039844

    输出#1

    YES
    NO
    YES
    NO
    YES
    NO
    YES

说明/提示

In the first test case, Boris's hair is initially [3,3,3][3,3,3]. Let us describe a sequence of 22 operations the barber can perform:

  • The barber uses the razor with size 11 on the segment [2,2][2,2]; hence Boris's hair becomes [3,1,3][3,1,3].
  • The barber uses the razor with size 22 on the segment [1,3][1,3]; hence Boris's hair becomes [2,1,2][2,1,2] which is the desired haircut.

In the third test case, no operation has to be done since Boris's hair is already as desired.

In the fourth test case, no cuts will be able to increase the third element in [1,1,1][1,1,1] in a way that the array becomes [1,1,2][1,1,2].

在第一个测试用例中,Boris 的头发初始为 [3,3,3][3,3,3]。下面描述理发师可以执行的一组共 22 次操作:

  • 理发师在区间 [2,2][2,2] 上使用尺寸为 11 的剃刀;因此 Boris 的头发变为 [3,1,3][3,1,3]。
  • 理发师在区间 [1,3][1,3] 上使用尺寸为 22 的剃刀;因此 Boris 的头发变为 [2,1,2][2,1,2],即目标发型。

在第三个测试用例中,无需执行任何操作,因为 Boris 的头发已符合要求。

在第四个测试用例中,无法通过任何剪发操作使 [1,1,1][1,1,1] 中的第三个元素增大,从而将数组变为 [1,1,2][1,1,2]。

输入解题思路,AI测评打分。不知道怎么写?

首页