Spectral::Cup 2026 Round 2 (Codeforces Round 1100, Div. 1 + Div. 2)
C1
我们来翻转(简单版)
We Be Flipping (Easy Version)
Codeforces
900
原题
← BC2 →

我们来翻转(简单版)AI (CI翻译)

This is the easy version of the problem. The difference between the versions is that in this version, you must minimise the sum. You can hack only if you solved all versions of this problem.

这是本题的简单版本。两个版本的区别在于:在本版本中,你需要使数组元素之和最小。仅当你解决了本题的所有版本后,才能进行 hack。AI (CI翻译)

You have an array $a$ of length $n$ which consists of non-zero (but possibly negative) integers. You will perform the following operation at most $n$ times (possibly none):

给定一个长度为 $n$ 的数组 $a$,其中每个元素都是非零整数(但可能为负数)。你最多执行 $n$ 次以下操作(也可以一次都不执行):AI (CI翻译)

  • select an index $i$ ($1 \le i \le n$) such that $a_i \gt 0$
  • then for each $j$ where $1 \le j \le i$ do $a_j := -a_j$.
  • 选择一个下标 $i$($1 \le i \le n$),满足 $a_i \gt 0$;
  • 对所有满足 $1 \le j \le i$ 的 $j$,执行 $a_j := -a_j$。
AI (CI翻译)

Output a valid sequence of operations of length at most $n$ which $\color{red}{\text{minimises}}$ the sum of $a$ at the end.

请输出一个长度不超过 $n$ 的合法操作序列,使得操作结束后数组 $a$ 的元素之和最小。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each testcase contains an integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the array $a$.

每个测试用例的第一行包含一个整数 $n$($2 \le n \le 2 \cdot 10^5$),表示数组 $a$ 的长度。AI (CI翻译)

The second line of each testcase contains $n$ integers $a_1,a_2,\ldots,a_n$ ($-10^9 \le a_i \le 10^9, a_i \ne 0$).

每个测试用例的第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($-10^9 \le a_i \le 10^9, a_i \ne 0$)。AI (CI翻译)

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

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each testcase, output a single integer $k$ ($0 \le k \le n$) — the number of operations you will perform.

对于每个测试用例,输出一个整数 $k$($0 \le k \le n$),表示你将执行的操作次数。AI (CI翻译)

Now output $k$ integers $b_1,\ldots,b_k$ where $b_i$ is the index you perform the $i$th operation on.

接下来输出 $k$ 个整数 $b_1,\ldots,b_k$,其中 $b_i$ 表示第 $i$ 次操作所选的下标。AI (CI翻译)

After performing the operations, the sum of $a$ should be minimal.

执行这些操作后,数组 $a$ 的元素之和应当达到最小值。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first testcase, the sum is already minimised. So no operations are required.

在第一个测试用例中,数组元素之和已经最小,因此不需要执行任何操作。AI (CI翻译)

In the second testcase, the operations are made as follows:

在第二个测试用例中,操作过程如下:AI (CI翻译)

  • $[-1, -2, 3, -5, 4] \xrightarrow{i = 3} [\color{red}{1, 2, -3}, -5, 4]$
  • $[1, 2, -3, -5, 4] \xrightarrow{i = 5} [\color{red}{-1, -2, 3, 5, -4}]$
  • $[-1, -2, 3, 5, -4] \xrightarrow{i = 4} [\color{red}{1, 2, -3, -5}, -4]$
  • $[1, 2, -3, -5, -4] \xrightarrow{i = 2} [\color{red}{-1, -2}, -3, -5, -4]$
  • $[-1, -2, 3, -5, 4] \xrightarrow{i = 3} [\color{red}{1, 2, -3}, -5, 4]$
  • $[1, 2, -3, -5, 4] \xrightarrow{i = 5} [\color{red}{-1, -2, 3, 5, -4}]$
  • $[-1, -2, 3, 5, -4] \xrightarrow{i = 4} [\color{red}{1, 2, -3, -5}, -4]$
  • $[1, 2, -3, -5, -4] \xrightarrow{i = 2} [\color{red}{-1, -2}, -3, -5, -4]$
AI (CI翻译)

This has a sum of $-15$, which is the minimum possible.

最终元素之和为 $-15$,这是可能达到的最小值。AI (CI翻译)

样例

Input #1
3
5
-1 -2 -3 -5 -4
5
-1 -2 3 -5 4
4
5 7 10 19
Output #1
0

4
3 5 4 2
1
4
InputCopy OutputCopy
题目信息
题号
2229C1
时间限制
2 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。