非高位元素AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given integers $N,K$ and an integer sequence $A=(A_1,A_2,\ldots,A_K)$ of length $K$. It is guaranteed that each element of $A$ is between $1$ and $N$, inclusive, and all elements are distinct.
给定整数 $N,K$ 以及一个长度为 $K$ 的整数序列 $A=(A_1,A_2,\ldots,A_K)$。保证 $A$ 中的每个元素都在 $1$ 到 $N$(含)之间,且所有元素互不相同。AI (CI翻译)
For a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$, define $f(P)$ as follows.
对于 $(1,2,\ldots,N)$ 的一个排列 $P=(P_1,P_2,\ldots,P_N)$,定义 $f(P)$ 如下。AI (CI翻译)
- The maximum number of times the following operation can be performed on
$P$. - Choose
$2\le i\le N$satisfying$P_i < \max(P_1,P_2,\ldots,P_{i-1})$, and move$P_i$to the front. That is, replace$P$with$(P_i,P_1,P_2,\ldots,P_{i-1},P_{i+1},\ldots,P_N)$.
- 对
$P$最多可以执行下述操作的次数。 - 选择满足
$2\le i\le N$且$P_i < \max(P_1,P_2,\ldots,P_{i-1})$的$i$,并将$P_i$移到最前面。也就是说,将$P$替换为$(P_i,P_1,P_2,\ldots,P_{i-1},P_{i+1},\ldots,P_N)$。
There are $(N-K)!$ permutations $P$ of $(1,2,\ldots,N)$ satisfying $P_i=A_i$ for $i=1,2,\ldots,K$. Find the sum, modulo $998244353$, of $f(P)$ over all such permutations.
满足 $P_i=A_i$(对于 $i=1,2,\ldots,K$)的 $(1,2,\ldots,N)$ 的排列 $P$ 共有 $(N-K)!$ 个。求所有这些 $P$ 的 $f(P)$ 之和,结果对 $998244353$ 取模。AI (CI翻译)
You are given $T$ test cases; solve each of them.
给定 $T$ 组测试数据,请分别求出每组的答案。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\le T\le 10^5$$1\le K\le N$- The sum of
$N$over all test cases is at most$5\times 10^5$. $1\le A_i\le N$- All elements of
$A$are distinct. - All input values are integers.
$1\le T\le 10^5$$1\le K\le N$- 所有测试数据中的
$N$之和不超过$5\times 10^5$。 $1\le A_i\le N$$A$中的所有元素互不相同。- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试数据按以下格式给出:AI (CI翻译)
N K
A_1 A_2 \ldots A_K
N K
A_1 A_2 \ldots A_KAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer for the test cases in order, separated by newlines.
按顺序输出各组测试数据的答案,每个答案占一行。AI (CI翻译)
样例
3
3 1
1
4 2
3 2
10 3
2 1 7
2
6
1382640
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。