#P7217. [JOISC 2020] 収穫
[JOISC 2020] 収穫
Background
JOI is the owner of the IOI manor.
Problem Description
There are employees in the IOI manor, and there are apple trees along the shore of a lake with perimeter .
Employee is located meters clockwise from the northernmost point of the lake. Apple tree is located meters clockwise from the northernmost point of the lake.
For special reasons, each apple tree can have at most one apple. At the initial moment, each apple tree has apple. If the apple on a tree is picked, then exactly s later an apple will grow again.
At the initial moment, each employee is at their original position. At each time moment, they walk meter clockwise. When they encounter an apple tree with a ripe apple, they will pick the apple.
Now JOI gives queries. Query is:
- Ask how many apples employee has harvested after time ends.
Input Format
The first line contains four integers , representing the number of employees, the number of apple trees, the perimeter of the lake, and the time interval for apples to become ripe again.
The second line contains integers as described above.
The third line contains integers as described above.
The fourth line contains an integer , representing the number of queries.
The next lines each contain two integers , representing one query.
Output Format
Output lines, each containing one integer, representing the answer.
3 2 7 3
1 4 6
0 5
3
1 7
2 3
3 8
2
1
1
5 3 20 6
0 4 8 12 16
2 11 14
9
4 1932
2 93787
1 89
5 98124798
1 2684
1 137598
3 2
3 8375
4 237
146
7035
7
7359360
202
10320
0
628
18
8 15 217 33608
0 12 71 96 111 128 152 206
4 34 42 67 76 81 85 104 110 117 122 148 166 170 212
14
2 223544052420046341
3 86357593875941375
4 892813012303440034
1 517156961659770735
7 415536186438473633
6 322175014520330760
7 557706040951533058
6 640041274241532527
5 286263974600593111
8 349405886653104871
1 987277313830536091
5 989137777159975413
2 50689028127994215
7 445686748471896881
33230868503053
3
5
1
123542793648997
8
165811220737767
8
7
1
1
7
7535161012043
132506837660717
Hint
Explanation of Sample 1
- At time :
- Employee arrives at apple tree and picks the ripe apple.
- Employee arrives at apple tree and picks the ripe apple.
- At time :
- Employee arrives at apple tree , but there is no ripe apple.
After time ends, employee has picked apple in total, corresponding to the 2nd query of Sample 1.
- At time :
- Employee arrives at apple tree and picks the ripe apple.
- At time :
- Employee arrives at apple tree and picks the ripe apple.
- Employee arrives at apple tree , but there is no ripe apple.
After time ends, employee has picked apples in total, corresponding to the 1st query of Sample 1.
- At time :
- Employee arrives at apple tree and picks the ripe apple.
- Employee arrives at apple tree , but there is no ripe apple.
After time ends, employee has picked apple in total, corresponding to the 3rd query of Sample 1.
Subtasks
| Subtask | Special Property | Score |
|---|---|---|
| None |
Constraints
For of the testdata: , , , , , , , , .
Notes
Translated from The 19th Japanese Olympiad in Informatics Spring Training Camp Day3 B 収穫。
Translated by ChatGPT 5