#P8556. 心跳 加强版
心跳 加强版
Background
This problem is an enhanced version of Luogu September Monthly Contest II & NR I. E. Heartbeat. The only difference is that the constraints are changed to .
“From the clear beating sound, overlapping echoes and flowing longing are conveyed.
Let’s promise never to be apart again, and hope that no matter when, you will not be left lonely.”
When people are in love, their mood does not stay the same forever. Joy and sadness will become calm as time passes. What is most unforgettable is the feeling of “being moved,” the pleasant surprise from things never experienced before. Therefore, sometimes, losing some especially beautiful memories can instead make that thrilling feeling happen more often. But is it really worth losing those memories for that?
Problem Description
Herlde wants to explore the question above. She wants to do some statistics first, so she abstracts the problem.
For a sequence of length , we define the function:
- is the number of indices such that (that is, the number of prefix maximums).
Now, given , find how many sequences of length with values in satisfy:
- There exists a permutation such that: let denote the sequence obtained from by removing (i.e. ), and .
The answer should be taken modulo .
Input Format
One line with two positive integers .
Output Format
One line with one integer, representing the answer.
3 1
6
5 3
8
500000 100000
226048544
Hint
[Sample Explanation #2]
There are different possible :
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
[Constraints]
For all testdata, it is guaranteed that .
Herlde successfully computed the number of different kinds of love. But she will only experience one of them.
Translated by ChatGPT 5