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, a_1, a_2, \dots, a_N. The indices are considered modulo N, so a_{N+1} = a_1, a_{N+2} = a_2, \dots. Also, N = 4k + 2 for some natural number k. You are allowed the following operation: choose index i and then set a_i to be the median of a_{i+k+1}, a_{i+k+2}, a_{i+k+3}, \dots, a_{i+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 a_i 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

1 \le N \le 500
You are allowed up to 2\,500 operations in total, for each test case.

Subtask 1 [30%]

1 \le a_i \le 2

Subtask 2 [70%]

1 \le a_i \le N

Input Specification

The first line contains a single integer, N.
The next line contains N space-separated integers, a_1, a_2, \dots, a_N.

Output Specification

On the first line, output the number of operations used. This number must not exceed 2\,500.
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 a_i to v, which must be between 1 and N. You may use the second operation at most 10 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 4 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, a_3 becomes the median of 5, 1, 3. So the array becomes

3 4 3 2 5 1

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

3 4 3 2 3 1

In the third operation, a_4 becomes the median of 1, 3, 4. 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

There are no comments at the moment.