DMPG '19 G3 - A Round Problem

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

You have an array of N integers, a1,a2,,aN. The indices are considered modulo N, so aN+1=a1,aN+2=a2,. Also, N=4k+2 for some natural number k. You are allowed the following operation: choose index i and then set ai to be the median of ai+k+1,ai+k+2,ai+k+3,,ai+3k+1 (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 i and change ai to any number from 1 to N. However, you are only allowed to do this second operation up to 10 times. Can you make all the elements equal?

Constraints

1N500
You are allowed up to 2500 operations in total, for each test case.

Subtask 1 [30%]

1ai2

Subtask 2 [70%]

1aiN

Input Specification

The first line contains a single integer, N.
The next line contains N space-separated integers, a1,a2,,aN.

Output Specification

On the first line, output the number of operations used. This number must not exceed 2500.
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 i.
For the second operation, output 2 i v on a line, to indicate using the operation on index i to change ai to v, which must be between 1 and N. You may use the second operation at most 10 times.

Sample Input 1

Copy
6
3 4 4 2 5 1

Sample Output 1

Copy
4
2 1 4
2 4 4
2 5 4
2 6 4

Explanation for Sample 1

The array after each change is

Copy
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 4 times so this is valid.

Sample Input 2

Copy
6
3 4 4 2 5 1

Sample Output 2

Copy
5
1 3
1 5
1 4
1 2
1 6

Explanation for Sample 2

For the first operation, a3 becomes the median of 5,1,3. So the array becomes

Copy
3 4 3 2 5 1

For the next operation, a5 becomes the median of 3,4,3. So the array becomes

Copy
3 4 3 2 3 1

In the third operation, a4 becomes the median of 1,3,4. So the array becomes

Copy
3 4 3 3 3 1

And in the final two operations, the array becomes

Copy
3 3 3 3 3 1
3 3 3 3 3 3

Comments

There are no comments at the moment.