#P7322. 「PMOI-4」排列变换

    ID: 6569 远端评测题 1500ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学O2优化组合数学洛谷月赛

「PMOI-4」排列变换

Description

Given a constant kk. For a permutation aa of length nn, define

$$f(a)=\{\max_{1 \le i \le k} \{a_i\},\max_{2 \le i \le k+1} \{a_i\},\cdots,\max_{n-k+1 \le i \le n} \{a_i\}\}$$

For a sequence aa of length nn, define its weight w(a)w(a) as the number of distinct values in aa.

Now, ducati\text{ducati} wants to know, for all permutations pp of length nn, the sum of w(f(p))w(f(p)).

Input Format

One line contains two positive integers n,kn, k.

Output Format

Output one integer in one line, representing the answer.

Since the answer may be very large, you need to take it modulo 998244353998244353.

3 2
10
500000 200000
840847204

Hint

[Sample Explanation]

  • p={1,2,3}p=\{1,2,3\}, f(p)={2,3}f(p)=\{2,3\}, so w(f(p))=2w(f(p))=2.
  • p={1,3,2}p=\{1,3,2\}, f(p)={3,3}f(p)=\{3,3\}, so w(f(p))=1w(f(p))=1.
  • p={2,1,3}p=\{2,1,3\}, f(p)={2,3}f(p)=\{2,3\}, so w(f(p))=2w(f(p))=2.
  • p={2,3,1}p=\{2,3,1\}, f(p)={3,3}f(p)=\{3,3\}, so w(f(p))=1w(f(p))=1.
  • p={3,1,2}p=\{3,1,2\}, f(p)={3,2}f(p)=\{3,2\}, so w(f(p))=2w(f(p))=2.
  • p={3,2,1}p=\{3,2,1\}, f(p)={3,2}f(p)=\{3,2\}, so w(f(p))=2w(f(p))=2.

The answer is 2+1+2+1+2+2=102+1+2+1+2+2=10.

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (10pts): n8n \le 8.
  • Subtask 2 (10pts): n11n \le 11.
  • Subtask 3 (30pts): n100n \le 100.
  • Subtask 4 (20pts): n400n \le 400.
  • Subtask 5 (20pts): n4000n \le 4000.
  • Subtask 6 (10pts): no special constraints.

For 100%100\% of the data, 1kn5×1051 \le k \le n \le 5 \times 10^5.

[Notes]

  1. pp is a permutation of length nn if and only if every integer in [1,n][1,n] appears in pp exactly once.
    For example, {1,5,3,2,4}\{1,5,3,2,4\} and {4,2,1,3}\{4,2,1,3\} are permutations of length 55 and 44, respectively, while {1,2,2}\{1,2,2\} is not a permutation of length 33, {5,4,3,2,1}\{5,4,3,2,1\} is not a permutation of length 66, and {1.5,3,1}\{1.5,3,1\} is not a permutation of length 33.

  2. This problem is not difficult.

Translated by ChatGPT 5