#P10116. [LMXOI Round 1] Random
[LMXOI Round 1] Random
Background
LMX gives HQZ an interesting sequence. To understand LMX’s preferences, HQZ wants to solve the following problem.
Problem Description
Given an initial sequence of length that is all , we will perform the following operation times.
- Choose any position and change the number at that position to any integer between and .
That is, in total there are different operation sequences. For each different operation sequence, there is a corresponding resulting sequence.
Next, a matching sequence of length is given. You need to compute the total number of occurrences of this matching sequence across every resulting sequence. Note that if a resulting sequence contains multiple occurrences of the matching sequence, they should be counted repeatedly.
Since the answer is too large, you only need to output the answer modulo .
This problem uses a special method to generate the input data.
The generation format is: , where denotes the required number at position of sequence .
Input Format
The first line contains four integers , where is the length of sequence .
The second line contains two integers .
Output Format
Output one integer representing the answer.
3 2 2 2
1 1
4
2 1 2 2
1 1
12
10 3 114 51419
19 2
266405589
Hint
Sample Explanation #1
For the following operation sequences, sequence appears:
- produces the sequence .
- produces the sequence .
- produces the sequence .
- produces the sequence .
For of the data, it is guaranteed that , , and .
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| Subtask #1 | ||||
| Subtask #2 | None | |||
| Subtask #3 | ||||
| Subtask #4 | ||||
| Subtask #5 | ||||
| Subtask #6 | ||||
Translated by ChatGPT 5