Flip - MarisaOJ: Marisa Online Judge

Flip

Time limit: 1000 ms
Memory limit: 256 MB
Given two arrays a and b, each containing n distinct integers. Define an operation where you reverse the elements in a subarray [l...r] and swap the maximum and minimum values in that subarray. Your task is to determine the sequence of operations required to transform array a into array b. ### Input - The first line contains an integer n. - The second line contains n integers, the array a. - The third line contains n integers, the array b. ### Output - The first line should contain an integer q, the number of operations. - The next q lines should each contain two integers l and r, representing the subarray [l...r] to reverse. ### Constraints - 1≤ai,bi≤n≤4096. - 1≤q≤3×105. ### Sample Test Input: 424311234 Output 434231234 ### Subtasks - **Subtask 1 (20% of the points):** n≤100. - **Subtask 2 (40% of the points):** n≤2048. - **Subtask 3 (40% of the points):** No additional constraints.