#ARC149E. [ARC149E] Sliding Window Sort

[ARC149E] Sliding Window Sort

Score : 700700 points

Problem Statement

You are given positive integers NN, MM, and KK. Consider the following operation on a sequence of positive integers A=(A0,,AN1)A = (A_0, \ldots, A_{N-1}).

  • Do the following for k=0,1,,K1k=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)modNA_{(k+j)\bmod N} with xjx_j for each 0j<M0\leq j < M, where (x0,,xM1)(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.
  • 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)modNA_{(k+j)\bmod N} with xjx_j for each 0j<M0\leq j < M, where (x0,,xM1)(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=(B0,,BN1)B = (B_0, \ldots, B_{N-1}) of the integers from 11 through NN. Find the number of sequences AA of positive integers that will equal BB after performing the operation above, modulo 998244353998244353.

Constraints

  • 2N3×1052\leq N\leq 3\times 10^5
  • 2MN2\leq M\leq N
  • 1K1091\leq K\leq 10^9
  • 1BiN1\leq B_i\leq N
  • BiBjB_i\neq B_j if iji\neq j.

Input

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

NN MM KK

B0B_0 \ldots BN1B_{N-1}

Print

Print the number of sequences AA of positive integers that will equal BB after performing the operation, modulo 998244353998244353.

6 3 5
6 4 2 3 1 5
18

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

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

No sequence AA satisfies the condition.

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

All permutations of the integers from 11 through 2020 satisfy the condition.