CF2226G.Stop Spot

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array aa of size nn (1≤ai≤m1 \leq a_i \leq m).

Consider all m!m! permutations of the array [1,2,…,m][1, 2, \ldots, m]. For any permutation pp, define the array bpb_p as the array formed by concatenating the array aa and the permutation pp. More formally, bp=[a1,a2,…,an,p1,p2,…,pm]b_p = [a_1, a_2, \ldots, a_n, p_1, p_2, \ldots, p_m].

Let f(i)f(i) denote the number of permutations pp such that the array bpb_p contains exactly ii 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 353998\,244\,353.

∗^{\text{∗}}An array [c1,c2,…,ck][c_1, c_2, \ldots, c_k] is said to be palindromic if ci=ck+1−ic_i = c_{k+1-i} for all 1≤i≤k1 \le i \le k.

给你一个长度为 nn 的数组 aa(其中 1≤ai≤m1 \leq a_i \leq m)。

考虑数组 [1,2,…,m][1, 2, \ldots, m] 的所有 m!m! 种排列。对任意一个排列 pp,定义数组 bpb_p 为将数组 aa 与排列 pp 拼接所得的数组。更准确地说,bp=[a1,a2,…,an,p1,p2,…,pm]b_p = [a_1, a_2, \ldots, a_n, p_1, p_2, \ldots, p_m]。

令 f(i)f(i) 表示满足“数组 bpb_p 中恰好包含 ii 个偶长度回文子数组”的排列 pp 的个数。

你的任务是计算

∑i=010100f(i)i+1.\sum_{i=0}^{10^{100}} f(i)^{i+1}.

由于答案可能很大,需对 998 244 353998\,244\,353 取模。

∗^{\text{∗}} 数组 [c1,c2,…,ck][c_1, c_2, \ldots, c_k] 被称为回文数组,当且仅当对所有 1≤i≤k1 \le i \le k,均有 ci=ck+1−ic_i = c_{k+1-i}。

输入格式

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

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

The second line of each testcase contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤m1 \le a_i \le m) — the elements of the array.

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

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

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

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤m1 \le a_i \le m)—— 数组的元素。

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

输出格式

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

对于每个测试用例,在一行中输出一个整数——∑i=010100f(i)i+1\sum_{i=0}^{10^{100}} f(i)^{i+1} 对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#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

    输出#1

    6
    1
    1248960
    258
    14006753

说明/提示

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

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

  • p1=[1,2,3]p_1 = [1, 2, 3], bp1=[3,1,2,1,1,2,3]b_{p_1} = [3, 1, 2, 1, 1, 2, 3], and the number of palindromic subarrays of even length is 22.
  • p2=[1,3,2]p_2 = [1, 3, 2], bp2=[3,1,2,1,1,3,2]b_{p_2} = [3, 1, 2, 1, 1, 3, 2], and the number of palindromic subarrays of even length is 11.
  • p3=[2,1,3]p_3 = [2, 1, 3], bp3=[3,1,2,1,2,1,3]b_{p_3} = [3, 1, 2, 1, 2, 1, 3], and the number of palindromic subarrays of even length is 00.
  • p4=[2,3,1]p_4 = [2, 3, 1], bp4=[3,1,2,1,2,3,1]b_{p_4} = [3, 1, 2, 1, 2, 3, 1], and the number of palindromic subarrays of even length is 00.
  • p5=[3,1,2]p_5 = [3, 1, 2], bp5=[3,1,2,1,3,1,2]b_{p_5} = [3, 1, 2, 1, 3, 1, 2], and the number of palindromic subarrays of even length is 00.
  • p6=[3,2,1]p_6 = [3, 2, 1], bp6=[3,1,2,1,3,2,1]b_{p_6} = [3, 1, 2, 1, 3, 2, 1], and the number of palindromic subarrays of even length is 00.

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

在第一个测试用例中,n=4n=4,m=3m=3,且 a=[3,1,2,1]a=[3,1,2,1]。

我们列出所有排列,并计算每个排列对应数组中长度为偶数的回文子数组的个数:

  • p1=[1,2,3]p_1 = [1, 2, 3],bp1=[3,1,2,1,1,2,3]b_{p_1} = [3, 1, 2, 1, 1, 2, 3],长度为偶数的回文子数组个数为 22。
  • p2=[1,3,2]p_2 = [1, 3, 2],bp2=[3,1,2,1,1,3,2]b_{p_2} = [3, 1, 2, 1, 1, 3, 2],长度为偶数的回文子数组个数为 11。
  • p3=[2,1,3]p_3 = [2, 1, 3],bp3=[3,1,2,1,2,1,3]b_{p_3} = [3, 1, 2, 1, 2, 1, 3],长度为偶数的回文子数组个数为 00。
  • p4=[2,3,1]p_4 = [2, 3, 1],bp4=[3,1,2,1,2,3,1]b_{p_4} = [3, 1, 2, 1, 2, 3, 1],长度为偶数的回文子数组个数为 00。
  • p5=[3,1,2]p_5 = [3, 1, 2],bp5=[3,1,2,1,3,1,2]b_{p_5} = [3, 1, 2, 1, 3, 1, 2],长度为偶数的回文子数组个数为 00。
  • p6=[3,2,1]p_6 = [3, 2, 1],bp6=[3,1,2,1,3,2,1]b_{p_6} = [3, 1, 2, 1, 3, 2, 1],长度为偶数的回文子数组个数为 00。

因此,我们有 f(0)=4f(0) = 4,f(1)=1f(1) = 1,f(2)=1f(2) = 1,且对所有 i>2i > 2 有 f(i)=0f(i) = 0。故答案为 41+12+13=64^1 + 1^2 + 1^3 = 6。

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

首页