CF1635C.Differential Sorting

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn elements.

Your can perform the following operation no more than nn times: Select three indices x,y,zx,y,z (1≤x<y<z≤n)(1 \leq x \lt y \lt z \leq n) and replace axa_x with ay−aza_y - a_z. After the operation, ∣ax∣|a_x| need to be less than 101810^{18}.

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.

给你一个包含 nn 个元素的数组 aa。

你最多可以执行 nn 次以下操作:选择三个下标 x,y,zx, y, z(满足 1≤x<y<z≤n1 \leq x \lt y \lt z \leq n),并将 axa_x 替换为 ay−aza_y - a_z。操作后需满足 ∣ax∣<1018|a_x| < 10^{18}。

你的目标是使最终得到的数组为非递减序列。若存在多种解法,输出任意一种即可;若无法实现,则也需报告该情况。

输入格式

Each test contains multiple test cases. The first line will contain a single integer tt (1≤t≤10000)(1 \leq t \leq 10000) — the number of test cases. Then tt test cases follow.

The first line of each test case contains a single integer nn (3≤n≤2⋅105)(3 \leq n \leq 2 \cdot 10^5) — the size of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots ,a_n (−109≤ai≤109)(-10^9 \leq a_i \leq 10^9), the elements of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤100001 \leq t \leq 10000),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5),表示数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots ,a_n(−109≤ai≤109-10^9 \leq a_i \leq 10^9),即数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print −1-1 in a single line if there is no solution. Otherwise in the first line you should print a single integer mm (0≤m≤n)(0 \leq m \leq n) — number of operations you performed.

Then the ii-th of the following mm lines should contain three integers x,y,zx,y,z (1≤x<y<z≤n)(1 \leq x \lt y \lt z \leq n)— description of the ii-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-1。否则,第一行应输出一个整数 mm (0≤m≤n)(0 \leq m \leq n),表示你执行的操作次数。

接下来的 mm 行中,第 ii 行应包含三个整数 x,y,zx,y,z (1≤x<y<z≤n)(1 \leq x \lt y \lt z \leq n),表示第 ii 次操作的描述。

若存在多个解,你可以输出任意一个。注意,本题不要求最小化操作次数。

输入输出样例

  • 输入#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][-6,-4,2,-1,2] after the first operation,

[−6,−4,−3,−1,2][-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.

在第一个例子中,数组在第一次操作后变为

[−6,−4,2,−1,2][-6,-4,2,-1,2],

在第二次操作后变为

[−6,−4,−3,−1,2][-6,-4,-3,-1,2]。

在第二个例子中,无论执行何种操作序列,都无法使数组变为有序。

在第三个例子中,数组本身已经有序,因此无需执行任何操作。

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

首页