GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 28 June 2022

[Solution] Equal Reversal Codeforces Solution | Codeforces Problem Solution 2022


F. Equal Reversal
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is an array a of length n. You may perform the following operation on it:

  • Choose two indices l and r where 1lrn and al=ar. Then, reverse the subsegment from the l-th to the r-th element, i. e. set [al,al+1,,ar1,ar] to [ar,ar1,,al+1,al].

You are also given another array b of length n which is a permutation of a. Find a sequence of at most n2 operations that transforms array a into b, or report that no such sequence exists.

Input

Each test contains multiple test cases. The first line contains a single integer t (1t100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (1n500) — the length of array a and b.

The second line of each test case contains n integers a1,a2,,an (1ain) — elements of the array a.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

The third line of each test case contains n integers b1,b2,,bn (1bin) — elements of the array b.

It is guaranteed that b is a permutation of a.

It is guaranteed that the sum of n over all test cases does not exceed 500.

Output

For each test case, output "NO" (without quotes) if it is impossible to turn a into b using at








 most n2 operations.

Otherwise, output "YES" (without quotes). Then output an integer k (0kn2) denoting the number of operations you will perform. Note that you don't have to minimize the number of operations.

Afterwards, output k lines. The i-th line should contain two integers li and ri (1lirin) — the left and right indices for the i-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