CF1702F.Equate Multisets

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Multiset —is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. Two multisets are equal when each value occurs the same number of times. For example, the multisets 2,2,4{2,2,4} and 2,4,2{2,4,2} are equal, but the multisets 1,2,2{1,2,2} and 1,1,2{1,1,2} — are not.

You are given two multisets aa and bb, each consisting of nn integers.

In a single operation, any element of the bb multiset can be doubled or halved (rounded down). In other words, you have one of the following operations available for an element xx of the bb multiset:

  • replace xx with x⋅2x \cdot 2,
  • or replace xx with ⌊x2⌋\lfloor \frac{x}{2} \rfloor (round down).

Note that you cannot change the elements of the aa multiset.

See if you can make the multiset bb become equal to the multiset aa in an arbitrary number of operations (maybe 00).

For example, if n=4n = 4, a=4,24,5,2a = {4, 24, 5, 2}, b=4,1,6,11b = {4, 1, 6, 11}, then the answer is yes. We can proceed as follows:

  • Replace 11 with 1⋅2=21 \cdot 2 = 2. We get b=4,2,6,11b = {4, 2, 6, 11}.
  • Replace 1111 with ⌊112⌋=5\lfloor \frac{11}{2} \rfloor = 5. We get b=4,2,6,5b = {4, 2, 6, 5}.
  • Replace 66 with 6⋅2=126 \cdot 2 = 12. We get b=4,2,12,5b = {4, 2, 12, 5}.
  • Replace 1212 with 12⋅2=2412 \cdot 2 = 24. We get b=4,2,24,5b = {4, 2, 24, 5}.
  • Got equal multisets a=4,24,5,2a = {4, 24, 5, 2} and b=4,2,24,5b = {4, 2, 24, 5}.

多重集(Multiset)—— 是一组数字,其中可以包含相等的元素,且数字的顺序无关紧要。当每个数值在两个多重集中出现的次数完全相同时,称这两个多重集相等。例如,多重集 {2,2,4}\{2,2,4\} 与 {2,4,2}\{2,4,2\} 相等,但多重集 {1,2,2}\{1,2,2\} 与 {1,1,2}\{1,1,2\} 不相等。

给定两个多重集 aa 和 bb,每个均由 nn 个整数组成。

在一次操作中,你可以对多重集 bb 中的任意一个元素执行加倍或**减半(向下取整)**操作。换言之,对多重集 bb 中的某个元素 xx,你可执行以下两种操作之一:

  • 将 xx 替换为 x⋅2x \cdot 2,
  • 或将 xx 替换为 ⌊x2⌋\lfloor \frac{x}{2} \rfloor(向下取整)。

注意:你不能修改多重集 aa 中的任何元素。

请判断:是否可以通过任意次数(可能为 00 次)的操作,使得多重集 bb 变为与多重集 aa 相等?

例如,若 n=4n = 4,a={4,24,5,2}a = \{4, 24, 5, 2\},b={4,1,6,11}b = \{4, 1, 6, 11\},则答案为“是”。我们可以按如下步骤操作:

  • 将 11 替换为 1⋅2=21 \cdot 2 = 2,得到 b={4,2,6,11}b = \{4, 2, 6, 11\}。
  • 将 1111 替换为 ⌊112⌋=5\lfloor \frac{11}{2} \rfloor = 5,得到 b={4,2,6,5}b = \{4, 2, 6, 5\}。
  • 将 66 替换为 6⋅2=126 \cdot 2 = 12,得到 b={4,2,12,5}b = \{4, 2, 12, 5\}。
  • 将 1212 替换为 12⋅2=2412 \cdot 2 = 24,得到 b={4,2,24,5}b = \{4, 2, 24, 5\}。
  • 此时得到的多重集 a={4,24,5,2}a = \{4, 24, 5, 2\} 与 b={4,2,24,5}b = \{4, 2, 24, 5\} 相等。

输入格式

The first line of input data contains a single integer tt (1≤t≤1041 \le t \le 10^4) —the number of test cases.

Each test case consists of three lines.

The first line of the test case contains an integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) —the number of elements in the multisets aa and bb.

The second line gives nn integers: a1,a2,…,ana_1, a_2, \dots, a_n (1≤a1≤a2≤⋯≤an≤1091 \le a_1 \le a_2 \le \dots \le a_n \le 10^9) —the elements of the multiset aa. Note that the elements may be equal.

The third line contains nn integers: b1,b2,…,bnb_1, b_2, \dots, b_n (1≤b1≤b2≤⋯≤bn≤1091 \le b_1 \le b_2 \le \dots \le b_n \le 10^9) — elements of the multiset bb. Note that the elements may be equal.

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

输入数据的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例由三行组成。

测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——多重集 aa 和 bb 中元素的个数。

测试用例的第二行包含 nn 个整数:a1,a2,…,ana_1, a_2, \dots, a_n(1≤a1≤a2≤⋯≤an≤1091 \le a_1 \le a_2 \le \dots \le a_n \le 10^9)——多重集 aa 的元素。注意,这些元素可能相等。

测试用例的第三行包含 nn 个整数:b1,b2,…,bnb_1, b_2, \dots, b_n(1≤b1≤b2≤⋯≤bn≤1091 \le b_1 \le b_2 \le \dots \le b_n \le 10^9)——多重集 bb 的元素。注意,这些元素可能相等。

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

输出格式

For each test case, print on a separate line:

  • YES if you can make the multiset bb become equal to aa,
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive answer).

对于每个测试用例,在单独一行中输出:

  • 如果可以使多重集 bb 变为等于 aa,则输出 YES;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    5
    4
    2 4 5 24
    1 4 6 11
    3
    1 4 17
    4 5 31
    5
    4 7 10 13 14
    2 14 14 26 42
    5
    2 2 4 4 4
    28 46 62 71 98
    6
    1 2 10 16 64 80
    20 43 60 74 85 99

    输出#1

    YES
    NO
    YES
    YES
    YES

说明/提示

The first example is explained in the statement.

In the second example, it is impossible to get the value 3131 from the numbers of the multiset bb by available operations.

In the third example, we can proceed as follows:

  • Replace 22 with 2⋅2=42 \cdot 2 = 4. We get b=4,14,14,26,42b = {4, 14, 14, 26, 42}.
  • Replace 1414 with ⌊142⌋=7\lfloor \frac{14}{2} \rfloor = 7. We get b=4,7,14,26,42b = {4, 7, 14, 26, 42}.
  • Replace 2626 with ⌊262⌋=13\lfloor \frac{26}{2} \rfloor = 13. We get b=4,7,14,13,42b = {4, 7, 14, 13, 42}.
  • Replace 4242 with ⌊422⌋=21\lfloor \frac{42}{2} \rfloor = 21. We get b=4,7,14,13,21b = {4, 7, 14, 13, 21}.
  • Replace 2121 with ⌊212⌋=10\lfloor \frac{21}{2} \rfloor = 10. We get b=4,7,14,13,10b = {4, 7, 14, 13, 10}.
  • Got equal multisets a=4,7,10,13,14a = {4, 7, 10, 13, 14} and b=4,7,14,13,10b = {4, 7, 14, 13, 10}.

第一个示例已在题目描述中说明。

在第二个示例中,无法通过对多重集 bb 中的数执行允许的操作得到数值 3131。

在第三个示例中,我们可以按如下方式操作:

  • 将 22 替换为 2⋅2=42 \cdot 2 = 4,得到 b={4,14,14,26,42}b = \{4, 14, 14, 26, 42\}。
  • 将 1414 替换为 ⌊142⌋=7\lfloor \frac{14}{2} \rfloor = 7,得到 b={4,7,14,26,42}b = \{4, 7, 14, 26, 42\}。
  • 将 2626 替换为 ⌊262⌋=13\lfloor \frac{26}{2} \rfloor = 13,得到 b={4,7,14,13,42}b = \{4, 7, 14, 13, 42\}。
  • 将 4242 替换为 ⌊422⌋=21\lfloor \frac{42}{2} \rfloor = 21,得到 b={4,7,14,13,21}b = \{4, 7, 14, 13, 21\}。
  • 将 2121 替换为 ⌊212⌋=10\lfloor \frac{21}{2} \rfloor = 10,得到 b={4,7,14,13,10}b = \{4, 7, 14, 13, 10\}。
  • 得到相等的多重集 a={4,7,10,13,14}a = \{4, 7, 10, 13, 14\} 和 b={4,7,14,13,10}b = \{4, 7, 14, 13, 10\}。

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

首页