Codeforces Round 1116 (Div. 1)
F
谁将见证终焉?
Who Will Witness the End?
Codeforces
3100
原题
← E2→

谁将见证终焉?AI (CI翻译)

Before her final sortie, Chtholly asks Willem three questions.

在她最后一次出征前,Chtholly 向 Willem 提出了三个问题。AI (CI翻译)

The third is this: when the end finally comes, who will remain to witness it?

第三个问题是:当终焉终于到来时,谁将留下来见证这一切?AI (CI翻译)

Willem cannot answer her directly. Instead, he draws a circle on the board, calling it the ring of all things, and writes down $n$ labeled integers $a_1,a_2,\ldots,a_n$. Every possible order around the ring describes a different way in which the world might reach its end.

Willem 无法直接回答她。于是,他在黑板上画了一个圆,将其称为万物之环,并写下 $n$ 个带标号的整数 $a_1,a_2,\ldots,a_n$。将这些整数以任意顺序排列在圆环上,就代表世界走向终焉的一种不同方式。AI (CI翻译)

Consider a permutation $p_1,p_2,\ldots,p_n$ of the integers from $1$ to $n$. Place the corresponding numbers on a circle in this order. The weight of the resulting circular arrangement is

考虑整数 $1$ 到 $n$ 的一个排列 $p_1,p_2,\ldots,p_n$。按照此顺序将对应的数字放置在圆上。得到的圆环排列的权值为AI (CI翻译)

$$ \prod_{i=1}^{n}(a_{p_i}+a_{p_{i+1}}), $$

$$ \prod_{i=1}^{n}(a_{p_i}+a_{p_{i+1}}), $$AI (CI翻译)

where $p_{n+1}=p_1$.

其中 $p_{n+1}=p_1$。AI (CI翻译)

Two permutations describe the same circular arrangement if one can be obtained from the other by a cyclic shift. Reversing an arrangement does not make it the same arrangement; in other words, reflected arrangements are considered different unless they also coincide after a cyclic shift.

如果一个排列可以通过循环移位得到另一个排列,则它们表示相同的圆环排列。反转一个排列不会使其变成相同的排列;换句话说,除非两个反射后的排列也能通过循环移位重合,否则它们被视为不同的排列。AI (CI翻译)

Find the sum of the weights of all distinct circular arrangements. Since the answer may be large, output it modulo $998\,244\,353$.

求所有不同圆环排列的权值之和。由于答案可能很大,请将其对 $998\,244\,353$ 取模后输出。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 test case contains one integer $n$ ($3 \le n \le 2\cdot 10^5$) — the number of labeled integers.

每个测试用例的第一行包含一个整数 $n$($3 \le n \le 2\cdot 10^5$),表示带标号整数的数量。AI (CI翻译)

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0 \le a_i \lt 998\,244\,353$).

第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($0 \le a_i \lt 998\,244\,353$)。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 test case, output one integer — the sum of the weights of all distinct circular arrangements, modulo $998\,244\,353$.

对于每个测试用例,输出一个整数,即所有不同圆环排列的权值之和对 $998\,244\,353$ 取模后的结果。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, there are two distinct circular arrangements. They can be represented by the permutations $[1,2,3]$ and $[1,3,2]$. Both have weight

在第一个测试用例中,有两种不同的圆环排列。它们可以分别用排列 $[1,2,3]$ 和 $[1,3,2]$ 表示。两者的权值均为AI (CI翻译)

$$ (1+2)(2+3)(3+1)=60, $$

$$ (1+2)(2+3)(3+1)=60, $$AI (CI翻译)

so the answer is $120$.

因此答案为 $120$。AI (CI翻译)

In the second test case, an arrangement has nonzero weight only if zeros and ones alternate around the circle. There are

在第二个测试用例中,只有当 $0$ 和 $1$ 在圆环上交替出现时,排列的权值才非零。这样的圆环排列共有AI (CI翻译)

$$ \frac{2\cdot3!\cdot3!}{6}=12 $$

$$ \frac{2\cdot3!\cdot3!}{6}=12 $$AI (CI翻译)

such circular arrangements: the factor $2$ chooses whether a linear representative starts with a zero or a one, and division by $6$ identifies cyclic shifts. Each arrangement has weight $1$. All other arrangements have weight $0$, so the answer is $12$.

种:因子 $2$ 表示线性表示可以从 $0$ 或 $1$ 开始,除以 $6$ 表示将循环移位视为同一种排列。每种排列的权值均为 $1$。其他排列的权值均为 $0$,因此答案为 $12$。AI (CI翻译)

样例

Input #1
3
3
1 2 3
6
0 1 0 1 0 1
10
114514 1919810 350234 11831 314159265 271828182 123456789 998244352 5201314 23333333
Output #1
120
12
265885269
InputCopy OutputCopy
题目信息
题号
2255F
时间限制
2 s
内存限制
256 MB
标签
FFT
数学

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