#L11251. [GESP202409 八级] 美丽路径
[GESP202409 八级] 美丽路径
CF2060G Bugged Sort
题目描述
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 and , both of length . All integers in the range from to appear exactly once in either or . In other words, the concatenated sequence is a permutation of length .
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 two indices and ( ), it swaps with , and swaps with .
Given sequences and , please determine if both sequences can be sorted in increasing order simultaneously after using Alice's swap function any number of times.
The concatenated sequence denotes the sequence .
A permutation of length contains all integers from to in some order.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases ( ). The description of the test cases follows.
The first line of each test case contains a single integer ( ).
The second line of each test case contains ( ).
The third line of each test case contains ( ).
It is guaranteed that all integers in the range appear exactly once in either or .
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
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.
输入输出样例 1
5
3
2 1 3
4 6 5
3
2 1 5
4 3 6
4
1 6 4 3
5 2 8 7
4
5 3 7 1
8 6 4 2
7
5 1 9 12 3 13 7
2 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 and . The arrays become and respectively. Both arrays are now sorted.