201494: [AtCoder]ARC149 E - Sliding Window Sort

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $700$ points

Problem Statement

You are given positive integers $N$, $M$, and $K$. Consider the following operation on a sequence of positive integers $A = (A_0, \ldots, A_{N-1})$.

  • Do the following for $k=0, 1, \ldots, K-1$ in this order.
    • Sort $A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}$ in ascending order. That is, replace $A_{(k+j)\bmod N}$ with $x_j$ for each $0\leq j < M$, where $(x_0, \ldots, x_{M-1})$ is the result of sorting $A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}$ in ascending order.

You are given a permutation $B = (B_0, \ldots, B_{N-1})$ of the integers from $1$ through $N$. Find the number of sequences $A$ of positive integers that will equal $B$ after performing the operation above, modulo $998244353$.

Constraints

  • $2\leq N\leq 3\times 10^5$
  • $2\leq M\leq N$
  • $1\leq K\leq 10^9$
  • $1\leq B_i\leq N$
  • $B_i\neq B_j$ if $i\neq j$.

Input

The input is given from Standard Input in the following format:

$N$ $M$ $K$
$B_0$ $\ldots$ $B_{N-1}$

Print

Print the number of sequences $A$ of positive integers that will equal $B$ after performing the operation, modulo $998244353$.


Sample Input 1

6 3 5
6 4 2 3 1 5

Sample Output 1

18

For instance, $A = (4,1,5,6,2,3)$ satisfies the condition. On this $A$, the operation will proceed as follows.

  • The action for $k=0$ changes $A$ to $(1,4,5,6,2,3)$.
  • The action for $k=1$ changes $A$ to $(1,4,5,6,2,3)$.
  • The action for $k=2$ changes $A$ to $(1,4,2,5,6,3)$.
  • The action for $k=3$ changes $A$ to $(1,4,2,3,5,6)$.
  • The action for $k=4$ changes $A$ to $(6,4,2,3,1,5)$, which equals $B$.

Sample Input 2

6 3 5
6 5 4 3 2 1

Sample Output 2

0

No sequence $A$ satisfies the condition.


Sample Input 3

20 20 149
13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12

Sample Output 3

401576539

All permutations of the integers from $1$ through $20$ satisfy the condition.

Input

题意翻译

### 题目描述 给定正整数 $N,M,K$。考虑对某个正整数数列 $A=(A_0,\dots,A_{N-1})$ 做如下操作: - 对所有 $k=0,1,\dots,K-1$ 依次做一遍如下操作: - 将 $A_{k\bmod N},A_{(k+1)\bmod N},\dots,A_{(k+M-1)\bmod N}$ 升序排序。 给定一个 $1\sim N$ 间整数的排列 $B=\{B_0,\dots,B_{N-1}\}$。求经过上述操作后与 $B$ 相同的 $A$ 的数量,对 $998244353$ 取模。 ### 样例解释 样例一: 以 $A=(4,1,5,6,2,3)$ 为例,它满足了条件。操作如下: - $k=0$ 时的操作将 $A$ 修改为 $(1,4,5,6,2,3)$。 - $k=1$ 时的操作将 $A$ 修改为 $(1,4,5,6,2,3)$。 - $k=2$ 时的操作将 $A$ 修改为 $(1,4,2,5,6,3)$。 - $k=3$ 时的操作将 $A$ 修改为 $(1,4,2,3,5,6)$。 - $k=4$ 时的操作将 $A$ 修改为 $(6,4,2,3,1,5)$。 样例二: 不存在满足条件的 $A$。 样例三: 所有 $1\sim20$ 间整数的排列都满足条件。

加入题单

上一题 下一题 算法标签: