CF2197B.Array and Permutation

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Array and Permutation

Given a permutation pp of length nn^{\text{∗}} and an array aa of length nn.

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

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

  • pi:=pi+1p_{i} := p_{i + 1};
  • pi+1:=pip_{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 pp is generating for the array aa.

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

Input

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

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

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

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

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

Output

For each test case, output "YES" if the permutation pp is generating for the array aa, 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=2i = 2 and pi+1:=pip_{i + 1} := p_{i}.

In the second test case, it is impossible to obtain aa from pp.

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

  • i=1i = 1 and pi:=pi+1p_{i} := p_{i + 1};
  • i=2i = 2 and pi+1:=pip_{i + 1} := p_{i}.

Samples

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
YES
NO
YES
NO
YES
YES

在线编程 IDE

建议全屏模式获得最佳体验