luogu#P5109. 归程
归程
Problem Description
dkw is playing a game called ION8102. The game is divided into the prologue, Chapter 1, and Chapter 2.
She has cleared the prologue with full health and has arrived at the first level of Chapter 1.
This level is called Return Journey. She needs to reach a specified location, and along the way she must pass through mechanical doors.
Each mechanical door has a keyhole, and only a special key can be inserted. Inside there are dial locks. Each dial lock must be turned to the target position exactly in order to open the door. The maximum scale of each dial is , with labels from to . The initial position of every dial lock is .
dkw has keys. Each key has rotation amounts , meaning that if this key is turned by one full circle, it will move the corresponding dial lock in the door by that many positions.
Each mechanical door also has a turn limit , which means that in total you can use keys to turn at most circles. Also, each key can only be turned forward, and only an integer number of circles can be turned.
The task requires opening these doors in order. Such an easy problem is of course solved instantly by dkw, but she is curious: for each door, how many different plans can open it successfully?
Two plans are different if and only if either the total number of circles is different, or the key used in some circle is different.
If you satisfy dkw’s curiosity, you will receive a big gift from her—100 points.
Input Format
The first line contains four positive integers , with meanings as described above.
The next lines each contain non-negative integers, representing the rotation amounts of this key in order.
The next lines: first a non-negative integer representing the turn limit, followed by non-negative integers representing the target positions of this door in order.
Output Format
For each query, output one line with one non-negative integer representing the answer to this query, modulo .
5 5 2 3
0 0
1 2
3 3
2 1
3 2
1 3 0
2 1 2
3 0 1
4 1 2
2 0 1
0
3
14
34
2
5 5 2 3
2 2
2 0
2 3
0 3
2 1
2 0 1
3 1 1
1 0 2
2 3 0
5 0 2
4
0
0
0
465
Hint
This problem uses subtasks.
- Subtask 1 (9pts): .
- Subtask 2 (16pts): .
- Subtask 3 (17pts): .
- Subtask 4 (19pts): .
- Subtask 5 (16pts): .
- Subtask 6 (23pts): .
For each test point, and are chosen from the corresponding relation in the table below.
Here, means that will not exceed this value.
| Index | v | maxk |
|---|---|---|
| 1 | 12 | |
| 2 | 8 | |
| 3 | 6 | |
| 4 | 5 | |
| 5 | 4 | |
| 6 | ||
| 7 | 3 | |
| 8 | ||
| 9 | ||
Translated by ChatGPT 5