#P7705. 「Wdsr-2.7」天才⑨与数学递推式
「Wdsr-2.7」天才⑨与数学递推式
Description
Cirno, the ice fairy who lives at Misty Lake, has always been known for her "wisdom". As a senior student at the temple school, Cirno is very familiar with mathematical recurrences.
One day, Teacher Keine wanted to test Cirno. So she wrote down a recurrence of length :
Here, and are given. However, since the first terms of the sequence are not fixed, there may be infinitely many recurrence sequences that satisfy this formula but have different initial terms. Keine plans to choose such sequences to test Cirno's understanding of sequences.
More specifically, Keine will tell Cirno the first terms of some one by one. Obviously, this determines an infinite sequence . Still, generating so many sequences is not very fun. So Keine creates an answer sequence , with initially.
Each time a new is given, Keine asks Cirno to add to the terms respectively.
Of course, Teacher Keine does not want to make things too hard. So for all numbers, you only need to output their values modulo , where is a given constant.
Formally, given . There are operations. In each operation, a set of is given. Define the infinite sequence by:
$$F_t=\begin{cases} G_t & t\le m \cr \sum_{i=1}^m K_iF_{t-i} & t>m \end{cases}$$Then for all , set . Finally, output the first terms of modulo .
Input Format
-
The first line contains four positive integers , with the meanings as described above.
-
The second line contains integers , representing the coefficients in the recurrence.
-
The next lines each contain integers , describing one operation.
Output Format
- Output a single line with integers, the values of .
5 3 2 114514
1 1
1 3 1 1
2 5 1 1
1 5 2 0
3 2 5 4 7
20 5 4 1919810
2 5 4 3
1 20 1 1 1 1
5 12 7 6 1 2
2 18 9 0 0 1
9 11 5 4 4 1
10 14 1 0 0 0
1 10 1 1 22 75 221 850 3176 11706 43324 160379 586060 249707 351705 931555 619201 372869 1800119 1750063
Hint
Sample Explanation
For sample :
-
Initially, .
-
The first step generates , and adds it to . Now .
-
The second step generates , and adds it to . Now .
-
The third step generates , and adds it to . Now .
For sample , we have neither a great explanation nor enough space, so we cannot write it here.
Constraints and Notes
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|}\hline \textbf{Subtask} & \bm{n} & \bm{m} & \bm{q}& \textbf{分值}\cr\hline 1 & n\le 10^4 & m\le 10 & q\le 10^3 & 10 \cr\hline 2 & n\le 10^5 & m=1 & q\le 10^5 & 20\cr\hline 3 & n\le 10^5 & m=2 & q\le 10^5 & 20\cr\hline 4 & \text{无特殊限制} & \text{无特殊限制} & \text{无特殊限制}& 50 \cr\hline \end{array}$$- For of the testdata: $1 \leq n\le 1\times 10^6;1\le q \leq 1.2 \times 10^5;1 \leq m \leq 15;1 \leq K_i,G_i,p \leq 10^8;1\le a\le b\le n$。
Translated by ChatGPT 5
京公网安备 11011102002149号