Codeforces Round 1095 (Div. 2)
G
Stop Spot
Codeforces
3000
原题
← F→
翻译中…

You are given an array $a$ of size $n$ ($1 \leq a_i \leq m$).

翻译中…

Consider all $m!$ permutations of the array $[1, 2, \ldots, m]$. For any permutation $p$, define the array $b_p$ as the array formed by concatenating the array $a$ and the permutation $p$. More formally, $b_p = [a_1, a_2, \ldots, a_n, p_1, p_2, \ldots, p_m]$.

翻译中…

Let $f(i)$ denote the number of permutations $p$ such that the array $b_p$ contains exactly $i$ palindromic$^{\text{∗}}$ subarrays of even length.

翻译中…

Your task is to compute $$ \sum_{i=0}^{10^{100}} f(i)^{i+1}.$$

翻译中…

Since the answer may be large, it should be computed modulo $998\,244\,353$.

翻译中…

$^{\text{∗}}$An array $[c_1, c_2, \ldots, c_k]$ is said to be palindromic if $c_i = c_{k+1-i}$ for all $1 \le i \le k$.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each testcase contains two integers $n$ and $m$ ($1 \le m \le n \le 10^6$).

翻译中…

The second line of each testcase contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the elements of the array.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each testcase, print a single integer on a new line — $ \sum_{i=0}^{10^{100}} f(i)^{i+1}$ modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, $n=4$, $m=3$, and $a=[3,1,2,1]$.

翻译中…

Let's list all permutations and calculate the number of palindromic subarrays of even length:

翻译中…
  • $p_1 = [1, 2, 3]$, $b_{p_1} = [3, 1, 2, 1, 1, 2, 3]$, and the number of palindromic subarrays of even length is $2$.
  • $p_2 = [1, 3, 2]$, $b_{p_2} = [3, 1, 2, 1, 1, 3, 2]$, and the number of palindromic subarrays of even length is $1$.
  • $p_3 = [2, 1, 3]$, $b_{p_3} = [3, 1, 2, 1, 2, 1, 3]$, and the number of palindromic subarrays of even length is $0$.
  • $p_4 = [2, 3, 1]$, $b_{p_4} = [3, 1, 2, 1, 2, 3, 1]$, and the number of palindromic subarrays of even length is $0$.
  • $p_5 = [3, 1, 2]$, $b_{p_5} = [3, 1, 2, 1, 3, 1, 2]$, and the number of palindromic subarrays of even length is $0$.
  • $p_6 = [3, 2, 1]$, $b_{p_6} = [3, 1, 2, 1, 3, 2, 1]$, and the number of palindromic subarrays of even length is $0$.
翻译中…

Thus, we have $f(0) = 4$, $f(1) = 1$, $f(2) = 1$, and $f(i) = 0$ for all $i \gt 2$. Hence, the answer is $4^1 + 1^2 + 1^3 = 6$.

翻译中…

样例

Input #1
5
4 3
3 1 2 1
1 1
1
9 4
4 1 2 1 3 3 1 2 1
6 3
1 1 3 1 1 1
10 6
4 4 1 2 1 3 3 1 2 1
Output #1
6
1
1248960
258
14006753
InputCopy OutputCopy
题目信息
题号
2226G
时间限制
2 s
内存限制
512 MB
标签
模拟
字符串
树

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