CF1144D.Equalize Them All

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa consisting of nn integers. You can perform the following operations arbitrary number of times (possibly, zero):

  1. Choose a pair of indices (i,j)(i, j) such that ij=1|i-j|=1 (indices ii and jj are adjacent) and set ai:=ai+aiaja_i := a_i + |a_i - a_j| ;
  2. Choose a pair of indices (i,j)(i, j) such that ij=1|i-j|=1 (indices ii and jj are adjacent) and set ai:=aiaiaja_i := a_i - |a_i - a_j| .

The value x|x| means the absolute value of xx . For example, 4=4|4| = 4 , 3=3|-3| = 3 .

Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it.

It is guaranteed that you always can obtain the array of equal elements using such operations.

Note that after each operation each element of the current array should not exceed 101810^{18} by absolute value.

输入格式

The first line of the input contains one integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of elements in aa .

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 0ai21050 \le a_i \le 2 \cdot 10^5 ), where aia_i is the ii -th element of aa .

输出格式

In the first line print one integer kk — the minimum number of operations required to obtain the array of equal elements.

In the next kk lines print operations itself. The pp -th operation should be printed as a triple of integers (tp,ip,jp)(t_p, i_p, j_p) , where tpt_p is either 11 or 22 ( 11 means that you perform the operation of the first type, and 22 means that you perform the operation of the second type), and ipi_p and jpj_p are indices of adjacent elements of the array such that 1ip,jpn1 \le i_p, j_p \le n , ipjp=1|i_p - j_p| = 1 . See the examples for better understanding.

Note that after each operation each element of the current array should not exceed 101810^{18} by absolute value.

If there are many possible answers, you can print any.

输入输出样例

  • 输入#1

    5
    2 4 6 6 6
    

    输出#1

    2
    1 2 3 
    1 1 2 
    
  • 输入#2

    3
    2 8 10
    

    输出#2

    2
    2 2 1 
    2 3 2 
    
  • 输入#3

    4
    1 1 1 1
    

    输出#3

    0
    
首页