#P7116. [NOIP2020] 微信步数
[NOIP2020] 微信步数
Description
Xiao C likes running, and he especially likes to climb the WeChat step leaderboard. For this, he made a plan to “farm” WeChat steps.
He comes to an open area. A person’s position in this area can be represented by a -dimensional integer coordinate . The area has size limits: the size of the -th dimension is , so a person in the area must satisfy ().
Xiao C plans that in the next days, he will start from a new position in the area each day to begin his step-farming plan (in other words, he will start once from every position in the area).
His plan is very simple. Every day he walks along a pre-defined route. The route of each day consists of moves, and each move can be described by and : if he is currently at , then in this move he will go to , where and . Xiao C will keep repeating this route until he walks out of the area, and then that day’s plan ends. (That is, after finishing step , if Xiao C is still inside the area, he returns to step and walks the route again from the beginning.)
Xiao C is very confident about his speed, so he does not care about the actual time spent. He only wants to know: after days, how many WeChat steps has he farmed in total. Please help him compute it.
Input Format
The first line contains two integers separated by a single space, representing the number of moves in the route and the number of dimensions of the area.
The next line contains integers separated by a single space, representing the size of the area.
The next lines each contain two integers separated by a single space, in order describing the direction of each move. The meaning is given in the statement.
Output Format
Output one line with a single integer, the answer. The answer may be very large; you only need to output it modulo .
If Xiao C’s plan would make it impossible for him to ever walk out of the area on some day, output one line with a single integer .
3 2
3 3
1 1
2 -1
1 1
21
5 4
6 8 6 5
3 1
2 1
1 1
2 1
2 -1
10265
见附件中的 walk/walk3.in
见附件中的 walk/walk3.ans
见附件中的 walk/walk4.in
见附件中的 walk/walk4.ans
Hint
[Sample #1 Explanation]
Starting from he will walk steps; starting from he will walk steps; starting from he will walk steps.
Starting from he will walk steps; starting from he will walk steps; starting from he will walk steps.
Starting from he will walk step; starting from he will walk step; starting from he will walk step.
In total, steps.
[Constraints]
| Test Point ID | |||
|---|---|---|---|
For all test points, it is guaranteed that , , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号