Codeforces Round 998 (Div. 3) |
---|
Finished |
Today, Alice has given Bob arrays for him to sort in increasing order again! At this point, no one really knows how many times she has done this.
Bob is given two sequences $$$a$$$ and $$$b$$$, both of length $$$n$$$. All integers in the range from $$$1$$$ to $$$2n$$$ appear exactly once in either $$$a$$$ or $$$b$$$. In other words, the concatenated$$$^{\text{∗}}$$$ sequence $$$a+b$$$ is a permutation$$$^{\text{†}}$$$ of length $$$2n$$$.
Bob must sort both sequences in increasing order at the same time using Alice's swap function. Alice's swap function is implemented as follows:
Given sequences $$$a$$$ and $$$b$$$, please determine if both sequences can be sorted in increasing order simultaneously after using Alice's swap function any number of times.
$$$^{\text{∗}}$$$The concatenated sequence $$$a+b$$$ denotes the sequence $$$[a_1, a_2, a_3, \ldots , b_1, b_2, b_3, \ldots]$$$.
$$$^{\text{†}}$$$A permutation of length $$$m$$$ contains all integers from $$$1$$$ to $$$m$$$ in some order.
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$$$ ($$$3 \le n \le 2 \cdot 10^5$$$).
The second line of each test case contains $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 2n$$$).
The third line of each test case contains $$$b_1,b_2,\ldots,b_n$$$ ($$$1 \le b_i \le 2n$$$).
It is guaranteed that all integers in the range $$$[1,2n]$$$ appear exactly once in either $$$a$$$ or $$$b$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
If it is possible to sort both sequences simultaneously, print "YES" on a new line. Otherwise, print "NO" on a new line.
You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses.
532 1 34 6 532 1 54 3 641 6 4 35 2 8 745 3 7 18 6 4 275 1 9 12 3 13 72 4 11 14 6 10 8
NO YES NO YES YES
In the first test case, it can be shown that it is impossible.
In the second test case, Bob can perform one operation with indices $$$i=1$$$ and $$$j=2$$$. The arrays become $$$[3,4,5]$$$ and $$$[1,2,6]$$$ respectively. Both arrays are now sorted.
Name |
---|