Codeforces Round 956 (Div. 2) and ByteRace 2024
D
Swap Dilemma
Codeforces
1700
原题
← CE →
翻译中…

Given two arrays of distinct positive integers $a$ and $b$ of length $n$, we would like to make both the arrays the same. Two arrays $x$ and $y$ of length $k$ are said to be the same when for all $1 \le i \le k$, $x_i = y_i$.

翻译中…

Now in one move, you can choose some index $l$ and $r$ in $a$ ($l \le r$) and swap $a_l$ and $a_r$, then choose some $p$ and $q$ ($p \le q$) in $b$ such that $r-l=q-p$ and swap $b_p$ and $b_q$.

翻译中…

Is it possible to make both arrays the same?

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the arrays $a$ and $b$.

翻译中…

The second line of each test case contains $n$ distinct integers $a_1,a_2,a_3,\ldots,a_n$ ($1 \le a_i \le 2 \cdot 10^5$) — the integers in the array $a$.

翻译中…

The third line of each test case contains $n$ distinct integers $b_1,b_2,b_3,\ldots,b_n$ ($1 \le b_i \le 2 \cdot 10^5$) — the integers in the array $b$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each testcase, print "YES" if the arrays $a$ and $b$ can be made the same. Otherwise, print "NO". can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

In the first testcase, you don't need to perform any operations since the arrays are same.

翻译中…

In the second testcase, it can be proven there exists no way to make the arrays same.

翻译中…

In the third testcase, one of the ways to make the arrays same is to first choose $l=1$, $r=3$, $p=1$, $q=3$ then choose $l=1$, $r=2$, $p=3$, $q=4$.

翻译中…

样例

Input #1
6
4
1 2 3 4
1 2 3 4
5
1 3 4 2 5
7 1 2 5 4
4
1 2 3 4
4 3 2 1
3
1 2 3
1 3 2
5
1 5 7 1000 4
4 1 7 5 1000
3
1 4 2
1 3 2
Output #1
YES
NO
YES
NO
NO
NO
InputCopy OutputCopy
题目信息
题号
1983D
时间限制
1 s
内存限制
256 MB
标签
构造
数据结构
分治
贪心
数学
排序

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