CF2043C Sums on Segments

题目描述

### 题目内容 给定一个长度为 $n$ 的数组 $a$,其中除了至多一个 $i \in [0,n)$ 满足 $|a_i| \neq 1$ 以外,其余全部项均满足 $|a_i|=1$。 求该数组中全部可能的子数组和,以升序输出。子数组是原数组中一段连续的数组。

输入格式

第一行一个整数 $t$($ 1 \le t \le 10^4$ ),表示测试用例数。 每个测试用例包含 $2$ 行,其中: - 第一行一个正整数 $n$( $1 \le n \le 2 \cdot 10^5$ ),表示数组长度 - 第二行 $n$ 个整数,表示 $a$ 中元素。 保证全部测试用例中 $n$ 的总和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试点,输出两行: - 第一行一个整数,表示可能的子数组和个数。 - 第二行以升序输出所有可能的子数组和。 即便多个子数组均可求出这个和,每一个值也只需要输出一次。

说明/提示

Let's define $ a[i,j] $ as the subarray of $ a $ from position $ i $ to position $ j $ . Consider the first test case of the example: - $ -1 $ is produced by $ a[2,2] $ ; - $ 0 $ is produced by the empty subarray; - $ 1 $ is produced by $ a[4,4] $ ; - $ 2 $ is produced by $ a[4,5] $ ; - $ 9 $ is produced by $ a[2,3] $ ; - $ 10 $ is produced by $ a[1,3] $ ; - $ 11 $ is produced by $ a[3,4] $ ; - $ 12 $ is produced by $ a[3,5] $ .