CF2226G.Stop Spot
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of size n (1≤ai≤m).
Consider all m! permutations of the array [1,2,…,m]. For any permutation p, define the array bp as the array formed by concatenating the array a and the permutation p. More formally, bp=[a1,a2,…,an,p1,p2,…,pm].
Let f(i) denote the number of permutations p such that the array bp contains exactly i palindromic∗ 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 998244353.
∗An array [c1,c2,…,ck] is said to be palindromic if ci=ck+1−i for all 1≤i≤k.
给你一个长度为 n 的数组 a(其中 1≤ai≤m)。
考虑数组 [1,2,…,m] 的所有 m! 种排列。对任意一个排列 p,定义数组 bp 为将数组 a 与排列 p 拼接所得的数组。更准确地说,bp=[a1,a2,…,an,p1,p2,…,pm]。
令 f(i) 表示满足“数组 bp 中恰好包含 i 个偶长度回文子数组”的排列 p 的个数。
你的任务是计算
i=0∑10100f(i)i+1.
由于答案可能很大,需对 998244353 取模。
∗ 数组 [c1,c2,…,ck] 被称为回文数组,当且仅当对所有 1≤i≤k,均有 ci=ck+1−i。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
The first line of each testcase contains two integers n and m (1≤m≤n≤106).
The second line of each testcase contains n integers a1,a2,…,an (1≤ai≤m) — the elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤m≤n≤106)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤m)—— 数组的元素。
保证所有测试用例的 n 之和不超过 106。
输出格式
For each testcase, print a single integer on a new line — $ \sum_{i=0}{10{100}} f(i)^{i+1}$ modulo 998244353.
对于每个测试用例,在一行中输出一个整数——∑i=010100f(i)i+1 对 998244353 取模的结果。
输入输出样例
输入#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=4, m=3, and a=[3,1,2,1].
Let's list all permutations and calculate the number of palindromic subarrays of even length:
- p1=[1,2,3], bp1=[3,1,2,1,1,2,3], and the number of palindromic subarrays of even length is 2.
- p2=[1,3,2], bp2=[3,1,2,1,1,3,2], and the number of palindromic subarrays of even length is 1.
- p3=[2,1,3], bp3=[3,1,2,1,2,1,3], and the number of palindromic subarrays of even length is 0.
- p4=[2,3,1], bp4=[3,1,2,1,2,3,1], and the number of palindromic subarrays of even length is 0.
- p5=[3,1,2], bp5=[3,1,2,1,3,1,2], and the number of palindromic subarrays of even length is 0.
- p6=[3,2,1], bp6=[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>2. Hence, the answer is 41+12+13=6.
在第一个测试用例中,n=4,m=3,且 a=[3,1,2,1]。
我们列出所有排列,并计算每个排列对应数组中长度为偶数的回文子数组的个数:
- p1=[1,2,3],bp1=[3,1,2,1,1,2,3],长度为偶数的回文子数组个数为 2。
- p2=[1,3,2],bp2=[3,1,2,1,1,3,2],长度为偶数的回文子数组个数为 1。
- p3=[2,1,3],bp3=[3,1,2,1,2,1,3],长度为偶数的回文子数组个数为 0。
- p4=[2,3,1],bp4=[3,1,2,1,2,3,1],长度为偶数的回文子数组个数为 0。
- p5=[3,1,2],bp5=[3,1,2,1,3,1,2],长度为偶数的回文子数组个数为 0。
- p6=[3,2,1],bp6=[3,1,2,1,3,2,1],长度为偶数的回文子数组个数为 0。
因此,我们有 f(0)=4,f(1)=1,f(2)=1,且对所有 i>2 有 f(i)=0。故答案为 41+12+13=6。
输入解题思路,AI测评打分。不知道怎么写?