CF1144D.Equalize Them All
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
- Choose a pair of indices (i,j) such that ∣i−j∣=1 (indices i and j are adjacent) and set ai:=ai+∣ai−aj∣;
- Choose a pair of indices (i,j) such that ∣i−j∣=1 (indices i and j are adjacent) and set ai:=ai−∣ai−aj∣.
The value ∣x∣ means the absolute value of x. For example, ∣4∣=4, ∣−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 1018 by absolute value.
给你一个包含 n 个整数的数组 a。你可以任意次(包括零次)执行以下操作:
- 选择一对下标 (i,j),满足 ∣i−j∣=1(即下标 i 和 j 相邻),并令 ai:=ai+∣ai−aj∣;
- 选择一对下标 (i,j),满足 ∣i−j∣=1(即下标 i 和 j 相邻),并令 ai:=ai−∣ai−aj∣。
其中 ∣x∣ 表示 x 的绝对值。例如,∣4∣=4,∣−3∣=3。
你的任务是求出使数组所有元素相等所需的最少操作次数,并输出实现该目标的操作序列。
保证总能通过上述操作使数组所有元素相等。
注意:每次操作后,当前数组中每个元素的绝对值均不应超过 1018。
输入格式
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of elements in a.
The second line of the input contains n integers a1,a2,…,an (0≤ai≤2⋅105), where ai is the i-th element of a.
输入的第一行包含一个整数 n(1≤n≤2⋅105)—— 表示数组 a 的元素个数。
输入的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤2⋅105),其中 ai 是数组 a 的第 i 个元素。
输出格式
In the first line print one integer k — the minimum number of operations required to obtain the array of equal elements.
In the next k lines print operations itself. The p-th operation should be printed as a triple of integers (tp,ip,jp), where tp is either 1 or 2 (1 means that you perform the operation of the first type, and 2 means that you perform the operation of the second type), and ip and jp are indices of adjacent elements of the array such that 1≤ip,jp≤n, ∣ip−jp∣=1. See the examples for better understanding.
Note that after each operation each element of the current array should not exceed 1018 by absolute value.
If there are many possible answers, you can print any.
第一行输出一个整数 k —— 使数组所有元素相等所需的最少操作次数。
接下来的 k 行输出具体的操作。第 p 个操作应表示为一个三元组 (tp,ip,jp),其中 tp 为 1 或 2(1 表示执行第一类操作,2 表示执行第二类操作),而 ip 和 jp 是数组中相邻元素的下标,满足 1≤ip,jp≤n 且 ∣ip−jp∣=1。参见样例以加深理解。
注意:每次操作后,当前数组中的每个元素的绝对值均不得超过 1018。
若存在多种可行答案,输出任意一种即可。
输入输出样例
输入#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测评打分。不知道怎么写?