DMPG '19 G3 - A Round Problem
View as PDFYou have an array of  integers, 
. The indices are considered modulo 
, so 
. Also, 
 for some natural number 
. You are allowed the following operation: choose index 
 and then set 
 to be the median of 
 (note that there are an odd number of numbers in this list). Can you perform a series of these operations so that all the elements become equal?
Unfortunately, this is often impossible. So you will be allowed to cheat a little! At any point in time, you can choose an index  and change 
 to any number from 
 to 
. However, you are only allowed to do this second operation up to 
 times. Can you make all the elements equal?
Constraints
You are allowed up to  operations in total, for each test case.
Subtask 1 [30%]
Subtask 2 [70%]
Input Specification
The first line contains a single integer, .
The next line contains  space-separated integers, 
.
Output Specification
On the first line, output the number of operations used. This number must not exceed .
On the remaining lines, print out your operations in order.
For the first operation, output 1 i on a line, to indicate using the operation on index .
For the second operation, output 2 i v on a line, to indicate using the operation on index  to change 
 to 
, which must be between 
 and 
. You may use the second operation at most 
 times.
Sample Input 1
6
3 4 4 2 5 1
Sample Output 1
4
2 1 4
2 4 4
2 5 4
2 6 4
Explanation for Sample 1
The array after each change is
4 4 4 2 5 1
4 4 4 4 5 1
4 4 4 4 4 1
4 4 4 4 4 4
The second operation is used only  times so this is valid.
Sample Input 2
6
3 4 4 2 5 1
Sample Output 2
5
1 3
1 5
1 4
1 2
1 6
Explanation for Sample 2
For the first operation,  becomes the median of 
. So the array becomes
3 4 3 2 5 1
For the next operation,  becomes the median of 
. So the array becomes
3 4 3 2 3 1
In the third operation,  becomes the median of 
. So the array becomes
3 4 3 3 3 1
And in the final two operations, the array becomes
3 3 3 3 3 1
3 3 3 3 3 3
Comments