#P15625. [ICPC 2022 Jakarta R] Sharing Bread

[ICPC 2022 Jakarta R] Sharing Bread

题目描述

There are NN toasters, numbered from 11 to NN, from left to right. Initially, each toaster has a single piece of bread in it. There are MM people, numbered from 11 to MM, who are one by one looking for bread among the toasters, starting from person 11, person 22, and so on.

Person ii starts looking from toaster aia_i (1aiN1 \leq a_i \leq N) and keeps going right until they found a toaster with a piece of bread in it. In other words, person ii is looking for the smallest jj such that aijNa_i \leq j \leq N and toaster jj contains bread. If such a toaster exists, then person ii will take the bread from that toaster and leave; the toaster becomes empty afterward. If such a toaster does not exist, then person ii will leave empty-handed.

A starting sequence (a1,a2,,aM)(a_1, a_2, \cdots, a_M) is fair if person ii starts looking from toaster aia_i and does not leave empty-handed, for all 1iM1 \leq i \leq M. Out of all NMN^M possible starting sequences, determine how many of them are fair modulo 998244353998\,244\,353.

输入格式

Input consists of two integers NN MM (1MN2000001 \leq M \leq N \leq 200\,000) in a single line representing the number of toasters and the number of people, respectively.

输出格式

Output an integer in a single line representing the number of fair starting sequence modulo 998244353998\,244\,353.

4 3
50
10 1
10
2 2
3

提示

Explanation for the sample input/output #1

One of the possible fair starting sequences is (4,2,2)(4, 2, 2). First, person 11 starts looking from toaster 44 and takes the bread from toaster 44. Then, person 22 starts looking from toaster 22 and takes the bread from toaster 22. Finally, person 33 will start looking from toaster 22, which is currently empty. Person 33 moves to toaster 33 and takes the bread from toaster 33. Since each person gets a piece of bread, the starting sequence (4,2,2)(4, 2, 2) is fair.

Another example of fair starting sequences are (1,1,1)(1, 1, 1), (1,1,2)(1, 1, 2), (2,3,4)(2, 3, 4), and (2,2,2)(2, 2, 2). Some of the possible starting sequences that are not fair are (3,3,3)(3, 3, 3), (3,4,3)(3, 4, 3), (4,4,1)(4, 4, 1), and (4,4,4)(4, 4, 4).

Explanation for the sample input/output #2

All starting sequences are fair.

Explanation for the sample input/output #3

The only starting sequence that is not fair is (2,2)(2,2). Person 11 starts looking from toaster 22 and takes the bread from toaster 22. Then, person 22 starts looking from toaster 22, which is currently empty. Since there is no more toaster to the right of toaster 22, person 22 will leave empty-handed.