[Solution] Equal Reversal Codeforces Solution | Codeforces Problem Solution 2022
There is an array of length . You may perform the following operation on it:
- Choose two indices and where and . Then, reverse the subsegment from the -th to the -th element, i. e. set to .
You are also given another array of length which is a permutation of . Find a sequence of at most operations that transforms array into , or report that no such sequence exists.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer () — the length of array and .
The second line of each test case contains integers () — elements of the array .
The third line of each test case contains integers () — elements of the array .
It is guaranteed that is a permutation of .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output "NO" (without quotes) if it is impossible to turn into using at
most operations.
Otherwise, output "YES" (without quotes). Then output an integer () denoting the number of operations you will perform. Note that you don't have to minimize the number of operations.
Afterwards, output lines. The -th line should contain two integers and () — the left and right indices for the -th operation.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
If there are multiple possible sequences of operations, you may output any of them.
No comments:
Post a Comment