AtCoder Regular Contest 217
B
非高位元素
Not High Element
AtCoder
⌀ 1834
原题
← AC →

非高位元素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)$。
AI (CI翻译)

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$ 中的所有元素互不相同。
  • 所有输入值均为整数。
AI (CI翻译)

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}_T
AI (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_K
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answer for the test cases in order, separated by newlines.

按顺序输出各组测试数据的答案,每个答案占一行。AI (CI翻译)

样例

Input #1
3
3 1
1
4 2
3 2
10 3
2 1 7
Output #1
2
6
1382640
Consider the first test case. The permutations $P$ of $(1,2,\ldots,N)$ satisfying $P_i=A_i$ for $i=1,2,\ldots,K$ are $P=(1,2,3)$ and $P=(1,3,2)$, giving two permutations. When $P=(1,2,3)$, no operation can be performed, so $f(P)=0$. When $P=(1,3,2)$, the operation can be performed twice as follows. - Choose $i=3$. Now $P=(2,1,3)$. - Choose $i=2$. Now $P=(1,2,3)$. The operation cannot be performed three or more times, so $f(P)=2$ in this case. Thus, the answer is $0+2=2$.
题目信息
题号
arc217_b
时间限制
2 s
内存限制
1024 MB

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