CF1672D.Cyclic Rotation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an array a of length n . You may perform the following operation any number of times:
- Choose two indices l and r where 1≤l<r≤n and al=ar . Then, set a[l…r]=[al+1,al+2,…,ar,al] .
You are also given another array b of length n which is a permutation of a . Determine whether it is possible to transform array a into an array b using the above operation some number of times.
输入格式
Each test contains multiple test cases. The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n ( 1≤n≤2⋅105 ) — the length of array a and b .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤n ) — elements of the array a .
The third line of each test case contains n integers b1,b2,…,bn ( 1≤bi≤n ) — elements of the array b .
It is guaranteed that b is a permutation of a .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105
输出格式
For each test case, print "YES" (without quotes) if it is possible to transform array a to b , and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
输入输出样例
输入#1
5 5 1 2 3 3 2 1 3 3 2 2 5 1 2 4 2 1 4 2 2 1 1 5 2 4 5 5 2 2 2 4 5 5 3 1 2 3 1 2 3 3 1 1 2 2 1 1
输出#1
YES YES NO YES NO
说明/提示
In the first test case, we can choose l=2 and r=5 to form [1,3,3,2,2] .
In the second test case, we can choose l=2 and r=4 to form [1,4,2,2,1] . Then, we can choose l=1 and r=5 to form [4,2,2,1,1] .
In the third test case, it can be proven that it is not possible to transform array a to b using the operation.