Equate Multisets

题目描述

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\}{2,2,4} and {2,4,2}\{2,4,2\}{2,4,2} are equal, but the multisets {1,2,2}\{1,2,2\}{1,2,2} and {1,1,2}\{1,1,2\}{1,1,2} — are not.

You are given two multisets aaa and bbb , each consisting of nnn integers.

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

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

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

See if you can make the multiset bbb become equal to the multiset aaa in an arbitrary number of operations (maybe 000 ).

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

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

输入格式

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

Each test case consists of three lines.

The first line of the test case contains an integer nnn ( 1≤n≤2⋅1051 \le n \le 2 \cdot 10^51≤n≤2⋅105 ) —the number of elements in the multisets aaa and bbb .

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

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

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

输出格式

For each test case, print on a separate line:

  • YES if you can make the multiset bbb become equal to aaa ,
  • 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).

样例 #1

样例输入 #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 $ 31 $ from the numbers of the multiset $ b $ by available operations.

In the third example, we can proceed as follows:

  • Replace 222 with 2⋅2=42 \cdot 2 = 42⋅2=4 . We get b={4,14,14,26,42}b = \{4, 14, 14, 26, 42\}b={4,14,14,26,42} .
  • Replace 141414 with ⌊142⌋=7\lfloor \frac{14}{2} \rfloor = 7⌊214​⌋=7 . We get b={4,7,14,26,42}b = \{4, 7, 14, 26, 42\}b={4,7,14,26,42} .
  • Replace 262626 with ⌊262⌋=13\lfloor \frac{26}{2} \rfloor = 13⌊226​⌋=13 . We get b={4,7,14,13,42}b = \{4, 7, 14, 13, 42\}b={4,7,14,13,42} .
  • Replace 424242 with ⌊422⌋=21\lfloor \frac{42}{2} \rfloor = 21⌊242​⌋=21 . We get b={4,7,14,13,21}b = \{4, 7, 14, 13, 21\}b={4,7,14,13,21} .
  • Replace 212121 with ⌊212⌋=10\lfloor \frac{21}{2} \rfloor = 10⌊221​⌋=10 . We get b={4,7,14,13,10}b = \{4, 7, 14, 13, 10\}b={4,7,14,13,10} .
  • Got equal multisets a={4,7,10,13,14}a = \{4, 7, 10, 13, 14\}a={4,7,10,13,14} and b={4,7,14,13,10}b = \{4, 7, 14, 13, 10\}b={4,7,14,13,10} .

中文翻译

给你两个长度为 nnn 的数组 aaa 和数组 bbb , 定义x的一次操作 (二选一):::

  • 把 xxx 替换成 x⋅2x \cdot 2x⋅2 ,

  • 把 xxx 替换成 ⌊x2⌋\lfloor \frac{x}{2} \rfloor⌊2x​⌋ (下取整).

aaa 数组不能做操作, bbb 数组不能做操作。

问经过若干操作,能否讲 bbb 数组 变成 aaa 数组? (数的顺序可以不一样)。

题解

先把 aaa 数组一直除以 222 (能除得尽就除) ,用一个 mapmapmap 统计个数,然后贪心地处理每个 bib_ibi​ ,能用就用。

#include<bits/stdc++.h>
using namespace std;
int n,a[200010],b[200010];
map<int,int> mp;
void solve(){mp.clear();cin>>n;for(int i=1;i<=n;i++){cin>>a[i];while(a[i]%2==0){a[i]/=2;}mp[a[i]]++;}for(int i=1;i<=n;i++)cin>>b[i];for(int i=1;i<=n;i++){int tmp=b[i];bool flag=0;while(tmp){if(!mp[tmp]){tmp/=2;continue;}mp[tmp]--;flag=1;break;}if(!flag){puts("NO");return ;}}for(auto it:mp){if(it.second>0){puts("NO");}}puts("YES");return ;
}
int main(){int TTT;cin>>TTT;while(TTT--){solve();}return 0;
}

【CF】Codeforces 1702F相关推荐

  1. 【cf】Codeforces 题解等汇总

    [cf]Codeforces Round #774 (Div. 2) 前4题 [cf]Codeforces Round #774 (Div. 2) 前4题_legend_yst的博客-CSDN博客 [ ...

  2. 【cf】Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

  3. cf端游界面更新显示服务器繁忙,【CF】UI界面更新了,那玩家期待已久的经典服务器呢?...

    原标题:[CF]UI界面更新了,那玩家期待已久的经典服务器呢? Hello,大家好,我是你们的灵狐姐,相信小伙伴们都知道新版本更新的所有内容了!目前体验服已经正式上线,相信不久后正服也是马上更新了!本 ...

  4. 【CF补题】【ABC】Codeforces Round #777 (Div. 2) C++代码

     A. Madoka and Math Dad [题意]求连续不带零且不相等位数的最大十进制数,使其位数之和为 n.有t个测试n [思考]根据样例我们就可以推测答案是121212...或212121. ...

  5. 【模拟】Codeforces 710C Magic Odd Square

    题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. ...

  6. 【模拟】Codeforces 705A Hulk

    题目链接: http://codeforces.com/problemset/problem/705/A 题目大意: 给一个数N(N<=100),N=1时输出"I hate it&qu ...

  7. 【模拟】Codeforces 711A Bus to Udayland

    题目链接: http://codeforces.com/problemset/problem/711/A 题目大意: N个字符串,每个字符串5位,找到第一个出现两个OO的并改成++输出YES和改后字符 ...

  8. 【记录CF】Codeforces Round #777 (Div. 2) A~C 题解

    目录 杂谈 A. Madoka and Math Dad B. Madoka and the Elegant Gift C. Madoka and Childish Pranks 杂谈 又是一场离谱掉 ...

  9. 【原创】Codeforces 39A C*++ Calculations

    Index Codeforces 39A C*++ Calculations 题意翻译 题目描述 输入格式 输出格式 输入输出样例 输入 #1 输出 #1 输入 #2 输出 #2 说明/提示 题意 分 ...

最新文章

  1. 十分钟了解 git 那些 “不常用” 命令
  2. 【JavaWeb】已解决:Resource interpreted as Stylesheet but transferred with MIME type text/html
  3. 使用postman创建Marketing Cloud的Contact
  4. sqlyog怎么设置默认值_物联网卡三网APN设置
  5. Tomcat JVM 初始化加大内存
  6. 步步深入MySQL:架构-gt;查询执行流程-gt;SQL解析顺序!
  7. 新发布 | Azure镜像市场正式上线
  8. 调整Redmine的用户显示格式
  9. List 去除重复数据的 5 种正确姿势!
  10. ahjesus sql2005+游标示例
  11. Java pta题库
  12. 单片机lcd1602程序 c语言,单片机I2C通信及LCD1602显示C程序
  13. Mac谷歌浏览器无法下载的解决方案
  14. python学生成绩管理程序设计总框图_学生成绩管理系统ER图+流程图+组织结构图-课程设计...
  15. Linux常用磁盘管理命令详解
  16. Acrel-EMS企业微电网能效管理平台在某食品加工厂35kV变电站案例分享-安科瑞 周莉娜
  17. python当前运行目录_Python获取运行目录与当前脚本目录的方法
  18. iOS 启动优化和安装包瘦身
  19. Vue3的生命周期的使用
  20. oracle dul误删数据,案例:Oracle dul数据挖掘 没有数据库备份非常规恢复truncate删除的数据表...

热门文章

  1. Linux备份与恢复
  2. L1-040 最 佳情侣身高差
  3. Linux —— 解决Docker内部容器DNS解析异常问题
  4. 星型模型和雪花型模型的区别
  5. ddos防火墙防御假人***测评
  6. vue项目开发目录结构说明
  7. 聊聊BIO,NIO和AIO
  8. 如何合理的布局关键词
  9. ubuntu 16.04 安装 uvcvideo驱动
  10. R.E.管理器Root Explorer v2.21.1汉化版