luogu#P9933. [NFLSPC #6] 9.pop_book();
[NFLSPC #6] 9.pop_book();
Background
Alek Sui is running laps on the playground. He feels upset when he sees someone overtake him, so he uses the following strategy.
Problem Description
On a circular playground of length , there are people. Person starts from position at time and moves at speed units per second. Now at time , Alek Sui is at position with speed , and he will follow the fastest person who passes by him. There are queries asking for the distance Alek Sui has moved at time . It can be proven that this is an integer.
Note: The position that is () units counterclockwise from position is called position . Everyone moves counterclockwise.
Multiple test cases.
Input Format
The first line contains an integer indicating the number of test cases. For each test case:
- The first line contains three integers , representing the number of people, the playground length, and the number of queries.
- The next lines each contain three integers , representing the starting position of person , the moving speed (units per second), and the starting time.
- The next lines each contain one integer , representing a query.
Output Format
For each query, output one line with an integer representing the answer.
1
3 30 8
0 2 1
6 5 2
25 4 4
1
5
9
10
11
12
13
14
0
8
16
19
23
27
31
36
Hint
For all testdata, , , , , . It is guaranteed that is non-decreasing and is strictly increasing.
- Subtask 1 ( points): .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): .
- Subtask 6 ( points): no special constraints.
Please note that the subtasks do not guarantee the order of magnitude of .
The I/O size of this problem is large. It is recommended to use scanf/printf, or disable synchronization for cin/cout, or use fast input and fast output.
Source: NFLSPC #6 I by Alex_Wei
Translated by ChatGPT 5