#FT0000206. Đổi chỗ đúng một lần – Bản 2 (One Time Swap 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đổi chỗ đúng một lần – Bản 2 (One Time Swap 2)
One Time Swap 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence of length , define , for every , as the sequence obtained by swapping the elements at positions and , leaving all other elements unchanged.
Construct one result for each of the index pairs, then sort all resulting sequences in nondecreasing lexicographical order. Call the sorted list .
Two different sequences are compared at the first position where their elements differ; the sequence with the smaller element is lexicographically smaller. Identical resulting sequences remain separate entries in when generated by different index pairs.
For each query containing , output any pair satisfying . If several index pairs produce the requested sequence, any one of them is accepted.
Input
- The first line contains integers , the length of the sequence and the number of queries.
- The next line contains exactly integers in their original order.
- Each of the next lines contains an integer , the -based rank in the sorted list of sequences.
Output
Print exactly lines. For query , print two space-separated integers such that and the array after swapping these positions equals the requested . Multiple valid answers are accepted.
Subtasks
- Subtask 1 (20 points): ; ; for every ; for each query.
- Subtask 2 (30 points): ; ; for every ; for each query.
- Subtask 3 (50 points): ; ; for every ; for each query.
Examples
Input
4 3
1 2 1 2
1
3
5
Output
2 3
2 4
1 2
Explanation
The six swap pairs produce , , , , , and .
In sorted order, these are , , , , , and . Thus, for ranks , the reported pairs , , and are all correct. Rank also accepts , illustrating why a special checker is necessary.