CF1144D.Equalize Them All

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 ∣i−j∣=1|i-j|=1 (indices ii and jj are adjacent) and set ai:=ai+∣ai−aj∣a_i := a_i + |a_i - a_j|;
  2. Choose a pair of indices (i,j)(i, j) such that ∣i−j∣=1|i-j|=1 (indices ii and jj are adjacent) and set ai:=ai−∣ai−aj∣a_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.

给你一个包含 nn 个整数的数组 aa。你可以任意次(包括零次)执行以下操作:

  1. 选择一对下标 (i,j)(i, j),满足 ∣i−j∣=1|i-j|=1(即下标 ii 和 jj 相邻),并令 ai:=ai+∣ai−aj∣a_i := a_i + |a_i - a_j|;
  2. 选择一对下标 (i,j)(i, j),满足 ∣i−j∣=1|i-j|=1(即下标 ii 和 jj 相邻),并令 ai:=ai−∣ai−aj∣a_i := a_i - |a_i - a_j|。

其中 ∣x∣|x| 表示 xx 的绝对值。例如,∣4∣=4|4| = 4,∣−3∣=3|-3| = 3。

你的任务是求出使数组所有元素相等所需的最少操作次数,并输出实现该目标的操作序列。

保证总能通过上述操作使数组所有元素相等。

注意:每次操作后,当前数组中每个元素的绝对值均不应超过 101810^{18}。

输入格式

The first line of the input contains one integer nn (1≤n≤2⋅1051 \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 (0≤ai≤2⋅1050 \le a_i \le 2 \cdot 10^5), where aia_i is the ii-th element of aa.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示数组 aa 的元素个数。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤2⋅1050 \le a_i \le 2 \cdot 10^5),其中 aia_i 是数组 aa 的第 ii 个元素。

输出格式

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 1≤ip,jp≤n1 \le i_p, j_p \le n, ∣ip−jp∣=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.

第一行输出一个整数 kk —— 使数组所有元素相等所需的最少操作次数。

接下来的 kk 行输出具体的操作。第 pp 个操作应表示为一个三元组 (tp,ip,jp)(t_p, i_p, j_p),其中 tpt_p 为 11 或 22(11 表示执行第一类操作,22 表示执行第二类操作),而 ipi_p 和 jpj_p 是数组中相邻元素的下标,满足 1≤ip,jp≤n1 \le i_p, j_p \le n 且 ∣ip−jp∣=1|i_p - j_p| = 1。参见样例以加深理解。

注意:每次操作后,当前数组中的每个元素的绝对值均不得超过 101810^{18}。

若存在多种可行答案,输出任意一种即可。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页