CF1635C.Differential Sorting
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of n elements.
Your can perform the following operation no more than n times: Select three indices x,y,z (1≤x<y<z≤n) and replace ax with ay−az . After the operation, ∣ax∣ need to be less than 1018 .
Your goal is to make the resulting array non-decreasing. If there are multiple solutions, you can output any. If it is impossible to achieve, you should report it as well.
输入格式
Each test contains multiple test cases. The first line will contain a single integer t (1≤t≤10000) — the number of test cases. Then t test cases follow.
The first line of each test case contains a single integer n (3≤n≤2⋅105) — the size of the array a .
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109) , the elements of a .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, print −1 in a single line if there is no solution. Otherwise in the first line you should print a single integer m (0≤m≤n) — number of operations you performed.
Then the i -th of the following m lines should contain three integers x,y,z (1≤x<y<z≤n) — description of the i -th operation.
If there are multiple solutions, you can output any. Note that you don't have to minimize the number of operations in this task.
输入输出样例
输入#1
3 5 5 -4 2 -1 2 3 4 3 2 3 -3 -2 -1
输出#1
2 1 2 3 3 4 5 -1 0
说明/提示
In the first example, the array becomes
[−6,−4,2,−1,2] after the first operation,
[−6,−4,−3,−1,2] after the second operation.
In the second example, it is impossible to make the array sorted after any sequence of operations.
In the third example, the array is already sorted, so we don't need to perform any operations.