CF2248B.Merge to Match

入门

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays aa and bb of lengths nn and mm, respectively. All n+mn + m integers in these arrays are distinct.

You can perform the following operation on aa any number of times (possibly, zero):

  • Choose two elements of aa with values xx and yy, where x≤yx \le y.
  • Delete these two elements from aa.
  • Insert one integer zz into aa such that x≤z≤yx \le z \le y.

After performing all operations, you may arrange the elements of aa in any order.

Determine whether it is possible to make aa equal to bb.

你有两个长度分别为 nn 和 mm 的数组 aa 和 bb。这两个数组中的全部 n+mn + m 个整数互不相同。

你可以对数组 aa 执行以下操作任意次(包括零次):

  • 选择 aa 中两个元素,其值分别为 xx 和 yy,且满足 x≤yx \le y;
  • 将这两个元素从 aa 中删除;
  • 向 aa 中插入一个整数 zz,使得 x≤z≤yx \le z \le y。

在执行完所有操作后,你可以将 aa 中的元素以任意顺序排列。

判断是否可能使 aa 变为与 bb 相等。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the lengths of the arrays aa and bb.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9).

The third line contains mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m (1≤bi≤1091 \le b_i \le 10^9).

It is guaranteed that all n+mn + m integers in the arrays aa and bb are distinct.

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

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5)—— 分别表示数组 aa 和 bb 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(1≤bi≤1091 \le b_i \le 10^9)。

保证数组 aa 和 bb 中全部 n+mn + m 个整数互不相同。

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

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

输出格式

For each test case, print "YES" if it is possible to make aa equal to bb, and "NO" otherwise.

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.

对于每个测试用例,如果可以使 aa 等于 bb,则输出 "YES";否则输出 "NO"。

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

输入输出样例

  • 输入#1

    11
    2 1
    1 3
    2
    3 2
    1 3 5
    2 4
    4 2
    1 3 5 7
    4 6
    4 2
    2 5 8 11
    1 10
    4 2
    1 4 7 9
    3 10
    5 2
    10 1 100 6 4
    90 5
    6 3
    1 4 10 20 30 40
    3 15 35
    4 2
    1 2 3 100
    4 5
    7 3
    1 8 3 30 18 12 25
    2 15 28
    4 1
    1 2 3 5
    4
    4 2
    1 3 5 6
    2 4

    输出#1

    YES
    NO
    YES
    NO
    NO
    YES
    YES
    NO
    YES
    YES
    YES

说明/提示

In the first test case, choose 11 and 33, delete them, and insert 22.

In the second test case, it can be shown that no sequence of operations can make aa equal to bb.

In the third test case, choose 11 and 55, delete them, and insert 44. Then, choose 33 and 77, delete them, and insert 66.

In the sixth test case, first choose 11 and 1010, delete them, and insert 55. Next, choose 66 and 100100, delete them, and insert 9090. Finally, choose 44 and 55, delete them, and insert 55.

In the seventh test case, for the pairs (1,4)(1,4), (10,20)(10,20), and (30,40)(30,40), delete both elements and insert 33, 1515, and 3535, respectively.

In the ninth test case, delete the pairs (1,3)(1,3), (8,18)(8,18), and (25,30)(25,30) and insert 22, 1515, and 2828, respectively. Then, delete 1212 and 1515 and insert 1515.

In the tenth test case, first choose 11 and 22, delete them, and insert 22. Then, choose 22 and 33, delete them, and insert 33. Finally, choose 33 and 55, delete them, and insert 44.

在第一个测试用例中,选择 11 和 33,删除它们,并插入 22。

在第二个测试用例中,可以证明:不存在任何操作序列能使 aa 等于 bb。

在第三个测试用例中,选择 11 和 55,删除它们,并插入 44;然后选择 33 和 77,删除它们,并插入 66。

在第六个测试用例中,首先选择 11 和 1010,删除它们,并插入 55;接着选择 66 和 100100,删除它们,并插入 9090;最后选择 44 和 55,删除它们,并插入 55。

在第七个测试用例中,对数对 (1,4)(1,4)、(10,20)(10,20) 和 (30,40)(30,40),分别删除两个元素,并插入 33、1515 和 3535。

在第九个测试用例中,删除数对 (1,3)(1,3)、(8,18)(8,18) 和 (25,30)(25,30),并分别插入 22、1515 和 2828;然后删除 1212 和 1515,并插入 1515。

在第十个测试用例中,首先选择 11 和 22,删除它们,并插入 22;然后选择 22 和 33,删除它们,并插入 33;最后选择 33 和 55,删除它们,并插入 44。

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

首页