#P17196. [KOI 2026 #2] 序列运算
[KOI 2026 #2] 序列运算
Problem Description
You are given a sequence of length and a sequence of length .
Sequence is a sequence formed by each of the integers appearing exactly once. Each element of sequence is between and , and all elements are pairwise distinct.
Let the sequence to be operated on be . Initially, sequence is the same as sequence . You may perform the following two operations on any number of times (possibly zero times).
-
Swap operation
Let .
Choose an integer such that and , and swap the values of the adjacent elements and .
-
Merge operation
Let .
Choose an integer such that , and merge the adjacent elements and into a single element .
In other words, after performing this operation, the length of sequence decreases by .
Determine whether it is possible to transform sequence into sequence using the given operations. If it is possible, output any sequence of operations that transforms into .
Note that you do not need to minimize the number of operations.
Input Format
The first line contains two integers and separated by spaces.
The second line contains integers separated by spaces.
The third line contains integers separated by spaces.
Output Format
If it is impossible to transform sequence into sequence , output NO on the first line.
If it is possible to transform sequence into sequence , output in the following format.
Output YES on the first line.
Output the number of operations on the second line. must satisfy:
In the next lines, output each operation in the order performed. Each operation must use one of the following two formats.
-
1 iPerform the swap operation on the -th and -th elements of sequence .
Let the length of sequence before this operation be . Then it must satisfy , and the value of the -th element of sequence must be less than the value of the -th element.
-
2 iPerform the merge operation on the -th and -th elements of sequence .
Let the length of sequence before this operation be . Then it must satisfy .
All positions are based on sequence before performing the corresponding operation, and the first position in the sequence is numbered .
After executing all operations in the given output in order, the resulting sequence must be exactly the same as sequence .
If multiple valid outputs exist, any one of them is accepted.
If sequence can be transformed into sequence using the given operations, it can be proven that there always exists an output satisfying all the conditions above.
4 2
1 4 2 3
3 1
YES
6
1 1
1 2
1 3
2 1
1 1
2 2
2 1
1 2
2
NO
4 4
3 2 1 4
3 1 2 4
NO
4 2
1 3 2 4
1 3
NO
Hint
Sample 1 Explanation
Sequence changes as follows:
$[1,4,2,3]\to[4,1,2,3]\to[4,2,1,3]\to[4,2,3,1]\to[2,3,1]\to[3,2,1]\to[3,1]$
Therefore, sequence can be transformed into sequence .
Constraints
- All given numbers are integers.
- Sequence is a permutation of , i.e. .
- For each integer (), .
- are pairwise distinct.
Subtasks
- ( points) .
- ( points) .
- ( points) .
- ( points) For each integer (), .
- ( points) .
- ( points) Sequence is a subsequence of sequence . In other words, there exist integers satisfying such that for each integer (), .
- ( points) .
- ( points) No additional constraints.
Translated by ChatGPT 5