CF1270G.Subset with Zero Sum

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn integers a1,a2,…,ana_1, a_2, \dots, a_n, such that for each 1≤i≤n1\le i \le n holds i−n≤ai≤i−1i-n\le a_i\le i-1.

Find some nonempty subset of these integers, whose sum is equal to 00. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them.

给你 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n,满足对每个 1≤i≤n1\le i \le n 都有 i−n≤ai≤i−1i-n\le a_i\le i-1。

请找出这些整数的一个非空子集,使得该子集内所有元素的和等于 00。在给定约束条件下,可以证明这样的子集一定存在。如果存在多个零和子集,输出任意一个即可。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1061 \le t \le 10^6). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1061\le n \le 10^6).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (i−n≤ai≤i−1i-n \le a_i \le i-1).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1061 \le t \le 10^6)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1061\le n \le 10^6)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(满足 i−n≤ai≤i−1i-n \le a_i \le i-1)。

保证所有测试用例的 nn 值之和不超过 10610^6。

输出格式

For each test case, output two lines.

In the first line, output ss (1≤s≤n1\le s \le n) — the number of elements in your subset.

In the second line, output ss integers i1,i2,…,isi_1, i_2, \dots, i_s (1≤ik≤n1\le i_k \le n). All integers have to be pairwise different, and ai1+ai2+⋯+aisa_{i_1} + a_{i_2} + \dots + a_{i_s} has to be equal to 00. If there are several possible subsets with zero-sum, you can find any of them.

对每个测试用例,输出两行。

第一行输出 ss(1≤s≤n1\le s \le n)—— 你所选子集的元素个数。

第二行输出 ss 个整数 i1,i2,…,isi_1, i_2, \dots, i_s(1≤ik≤n1\le i_k \le n)。所有整数必须两两不同,且需满足 ai1+ai2+⋯+ais=0a_{i_1} + a_{i_2} + \dots + a_{i_s} = 0。若存在多个零和子集,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    5
    0 1 2 3 4
    4
    -3 1 1 1

    输出#1

    1
    1 
    4
    1 4 3 2

说明/提示

In the first example, we get sum is a1=0a_1 = 0.

In the second example, we get sum is a1+a4+a3+a2=0a_1 + a_4 + a_3 + a_2 = 0.

在第一个例子中,我们得到的和为 a1=0a_1 = 0。

在第二个例子中,我们得到的和为 a1+a4+a3+a2=0a_1 + a_4 + a_3 + a_2 = 0。

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

首页