#P8555. 嘘月
嘘月
Background
“I can no longer recognize your eyes, and I am no longer thinking of your face;
you still did not say goodbye, and you turned into the night and left.”
Hilde Watching the Tide suddenly feels that this ever-rising tide is like continuously increasing passion: it keeps the time of a hot romance going, and excitement brings us even more passion. But the passion at the first meeting will eventually fade, and how many people can find an unchanging rhythm inside a cooling heartbeat and walk through this whole life?
Problem Description
Hilde wants to explore the question above, so she wants to do some statistics first, and she abstracts the problem.
For a permutation of length , we maintain an index , with initial value .
Repeat the following process:
- Choose an unmarked element among those with indices in , and mark it. If the marked number is larger than the previously marked number and , then increase by ; otherwise, end the process. Before the first marking, the previously marked number is considered to be .
We call such a permutation good:
- There exists some strategy such that after several operations, .
Now, given , find the proportion of good permutations of length among all permutations of length , modulo . In other words, if there are good permutations of length , you need to output modulo . If you do not understand how to take a rational number modulo, you can read this problem.
There are queries, and each query gives an .
Input Format
The first line contains two positive integers .
The second line contains positive integers, representing for each query. It is guaranteed that the queries are in increasing order and pairwise distinct.
Output Format
For each query, output one integer per line, the answer modulo .
5 3
1 2 3
291154603
249561089
1
50 5
4 7 9 14 17
344293672
864377042
192544332
688054502
97923957
Hint
Sample Explanation #1
The numbers of permutations that can make are respectively. There are permutations in total, so you need to output respectively. After taking modulo, they become the sample output.
When , the following are all permutations that can make :
$$\{1,2,3,4,5\},\{2,3,4,5,1\},\{1,3,4,5,2\},\{1,2,4,5,3\},\{1,2,3,5,4\}$$When , here are some permutations that can make :
And some permutations that cannot make :
Constraints
It is guaranteed that , , and the queries are pairwise distinct and sorted in increasing order.
$$\def\arraystretch{1.5} \begin{array}{c|c|c|c}\hline \textbf{Subtask ID}&\bm{~~~~~~~n\le~~~~~~~}&\textbf{~~~Special Constraints~~~}&\textbf{~~Score~~}\cr\hline \textsf1 & 5 &&7\cr\hline \textsf2 & 200&&23\cr\hline \textsf3 & 2\times 10^4 &m_i=1& 9\cr \hline \textsf4 & 2\times 10^4 &2m_i\ge n& 3\cr \hline \textsf5 & 2\times 10^4 &&12\cr\hline \textsf6 & &q=1&36\cr\hline \textsf7 & &&10\cr\hline \end{array}$$Hint: An solution can pass quite a few points.
Translated by ChatGPT 5