#P6073. 『MdOI R1』Epic Convolution
『MdOI R1』Epic Convolution
Background
Little Q is a genius and especially likes polynomials.
One day, Little K asked a question:
Given two sequences of length , find such that .
Little Q said to Little K: You are such a newbie. Isn’t this just an easy convolution? What did you learn FFT for?
Then Little K spent a month learning FFT and NTT, and went to ask Little Q another question:
Given two sequences of length , find such that .
Little Q said to Little K: You are such a newbie. Isn’t this just an easy convolution? What did you learn FFT for?
Then Little K spent another month learning FFT and NTT, and went to ask Little Q yet another question:
Given two sequences of length , find such that .
Little Q said to Little K: You are such a newbie. Isn’t this just an easy convolution? What did you learn FFT for?
Then he took a careful look and was stunned, realizing he could not solve this problem.
To totally defeat Little K, you need to tell him how to handle special cases.
Background
Little Q is a genius and especially likes polynomials.
One day, Little K asked a question:
Given two sequences of length , find such that .
Little Q said to Little K: You are such a newbie. Isn’t this just an easy convolution? What did you learn FFT for?
Then Little K spent a month learning FFT and NTT, and went to ask Little Q another question:
Given two sequences of length , find such that .
Little Q said to Little K: You are such a newbie. Isn’t this just an easy convolution? What did you learn FFT for?
Then Little K spent another month learning FFT and NTT, and went to ask Little Q yet another question:
Given two sequences of length , find such that .
Little Q said to Little K: You are such a newbie. Isn’t this just an easy convolution? What did you learn FFT for?
Then he took a careful look and was stunned, realizing he could not solve this problem.
To totally defeat Little K, you need to tell him how to handle special cases.
Problem Description
Given specific sequences , compute satisfying .
This problem has five subtasks. The first four subtasks give different forms of and ask you to compute . The fifth subtask does not depend on this equation, but it looks similar in form.
Note: all outputs in this problem should be taken modulo (, a prime).
Subtask 1 (4 pts):
Given an integer , you need to answer queries. Each query gives an integer .
For each query, and are as follows ():
You need to output the value of .
Subtask 2, 3 (16, 16 pts):
These two subtasks use the same form of sequences , but have different constraints. Please read the constraints carefully.
You need to answer queries. Each query gives two integers .
For each query, and are as follows ():
$$h_k=\begin{cases}0,&k<m\\\frac{(-1)^{k-m}}{(k-m)!},&k\geq m\end{cases}$$You need to output the value of .
Subtask 4 (32 pts):
You need to answer queries. Each query gives two integers .
For each query, and are as follows ():
You need to output the value of .
Subtask 5 (32 pts):
You need to answer queries. Each query gives two integers .
Note the meaning of below. Do not swap them.
$$\sum\limits_{k=0}^{m}(k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\sum\limits_{i=0}^{m-k}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}$$You need to output the value of the expression above.
Similar to the first four subtasks, the summation starts with a power term.
Input Format
The first line contains an integer , indicating the subtask number.
If :
The second line contains an integer , and the third line contains an integer .
Then follow lines, each containing an integer .
If :
The second line contains an integer .
Then follow lines, each containing two integers .
The meaning of all variables is given in the problem description.
Output Format
For each query, output one integer per line, indicating the answer.
1
5
2
2
3
1
33
2
2
4 2
18 7
440891256
841247136
4
2
4 2
20 9
65
429844531
5
2
4 2
30 12
58
475486366
Hint
Sample Explanation 1
In this sample, you need to solve Subtask 1, with .
In the first query, , then (omitting terms whose addend is ):
$$[g_0\ \ g_1\ \ g_2\ \ g_3\ \ g_4\ \ g_5]=[1\ \ 1\ \ 0\ \ 0\ \ 0\ \ 0]$$$$[h_0\ \ h_1\ \ h_2\ \ h_3\ \ h_4\ \ h_5]=[1\ \ 1\ \ 1\ \ 1\ \ 1\ \ 1]$$In the second query, , then:
$$[g_0\ \ g_1\ \ g_2\ \ g_3\ \ g_4\ \ g_5]=[1\ \ 1\ \ 1\ \ 0\ \ 0\ \ 0]$$$$[h_0\ \ h_1\ \ h_2\ \ h_3\ \ h_4\ \ h_5]=[1\ \ 1\ \ 1\ \ 1\ \ 1\ \ 1]$$Sample Explanation 2
In this sample, you need to solve Subtask 2, with .
In the first query, , then:
$$[g_0\ \ g_1\ \ g_2\ \ g_3\ \ g_4]=[\dfrac{1}{6}\ \ \dfrac{1}{24}\ \ \dfrac{1}{120}\ \ \dfrac{1}{720}\ \ \dfrac{1}{5040}]$$$$[h_0\ \ h_1\ \ h_2\ \ h_3\ \ h_4]=[0\ \ 0\ \ 1\ \ -1\ \ \dfrac{1}{2}]$$$$f_4=1^4\times g_1h_3+2^4\times g_2h_2=\dfrac{11}{120}$$After taking modulo , equals .
The second query has constraints that are too large, so no sample explanation is provided.
Sample Explanation 3
In this sample, you need to solve Subtask 4, with .
In the first query, , then:
$$[g_0\ \ g_1\ \ g_2\ \ g_3\ \ g_4]=[0\ \ \ 1\ \ \ 2\ \ \ \dfrac{3}{2}\ \ \dfrac{2}{3}]$$$$[h_0\ \ h_1\ \ h_2\ \ h_3\ \ h_4]=[1\ \ -1\ \ \dfrac{1}{2}\ \ -\dfrac{1}{6}\ \ \dfrac{1}{24}]$$$$f_4=1^4\times g_1h_3+2^4\times g_2h_2+3^4\times g_3h_1+4^4\times g_4h_0=65$$The second query has constraints that are too large, so no sample explanation is provided.
Sample Explanation 4
In this sample, you need to solve Subtask 5, with .
In the first query, , enumerate :
$$k=0,\ \ i=0:\ \ (k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}=\dfrac{1}{2}$$$$k=0,\ \ i=1:\ \ (k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}=9$$$$k=0,\ \ i=2:\ \ (k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}=36$$$$k=1,\ \ i=0:\ \ (k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}=-64$$$$k=1\ \ i=1:\ \ (k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}=-288$$$$k=2\ \ i=0:\ \ (k+1)^m\dfrac{(k+1)^{n+1}}{(k+1)!}\dfrac{\binom{2n+1}{i}(-1)^{m-k}}{(m-k-i)!(k+1)^i}=\dfrac{729}{2}$$Adding them all up gives .
The second query has constraints that are too large, so no sample explanation is provided.
Constraints
This problem uses bundled testdata, and different subtasks have different statements.
| Subtask ID | Points | |||
|---|---|---|---|---|
| 1 | 4 | |||
| 2 | 16 | |||
| 3 | ||||
| 4 (31-40) | 32 | |||
| 4 (51-60) | ||||
| 5 | ||||
All inputs are positive integers.
Translated by ChatGPT 5