Codeforces Round 1079 (Div. 2)
B
Array and Permutation
Codeforces
1100
原题
← AC →
翻译中…

Given a permutation $p$ of length $n$$^{\text{∗}}$ and an array $a$ of length $n$.

翻译中…

We call the permutation $p$ generating for the array $a$ if the array $a$ can be obtained from the permutation $p$ by applying some number of operations (possibly zero) of the following type:

翻译中…

Choose an index $i$ ($1 \le i \lt n$) and perform one of two replacements:

翻译中…
  • $p_{i} := p_{i + 1}$;
  • $p_{i + 1} := p_{i}$.
翻译中…

In other words, in one operation, you can choose two adjacent elements of the array and copy the value of one into the other.

翻译中…

You are required to report whether the permutation $p$ is generating for the array $a$.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^{5}$) — the length of the array and the permutation.

翻译中…

The second line of each test case contains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \le p_{i} \le n$) — the elements of the permutation.

翻译中…

The third line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_{i} \le n$) — the elements of the array.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^{5}$.

翻译中…

Output

翻译中…

For each test case, output "YES" if the permutation $p$ is generating for the array $a$, otherwise output "NO".

翻译中…

You may output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

翻译中…

Note

翻译中…

In the first test case, the array is generated from the permutation using one operation:

翻译中…
  • $i = 2$ and $p_{i + 1} := p_{i}$.
翻译中…

In the second test case, it is impossible to obtain $a$ from $p$.

翻译中…

In the third test case, it is necessary to perform $2$ operations:

翻译中…
  • $i = 1$ and $p_{i} := p_{i + 1}$;
  • $i = 2$ and $p_{i + 1} := p_{i}$.
翻译中…

样例

Input #1
6
3
1 2 3
1 2 2
4
3 1 2 4
3 4 2 2
5
1 3 2 5 4
3 3 3 5 4
7
3 7 4 2 1 6 5
3 3 4 4 5 6 5
7
1 2 3 4 5 6 7
7 7 7 7 7 7 7
7
1 3 2 7 5 4 6
2 2 7 7 7 5 6
Output #1
YES
NO
YES
NO
YES
YES
InputCopy OutputCopy
题目信息
题号
2197B
时间限制
1.5 s
内存限制
256 MB
标签
模拟
调度
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。