#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 kk-dimensional integer coordinate (a1,a2,,ak)(a_1, a_2, \ldots , a_k). The area has size limits: the size of the ii-th dimension is wiw_i, so a person in the area must satisfy 1aiwi1 \le a_i \le w_i (1ik1 \le i \le k).

Xiao C plans that in the next P=w1×w2××wkP = w_1 \times w_2 \times \cdots \times w_k 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 nn moves, and each move can be described by cic_i and did_i: if he is currently at (a1,a2,,aci,,ak)(a_1, a_2, \ldots , a_{c_i}, \ldots, a_k), then in this move he will go to (a1,a2,,aci+di,,ak)(a_1, a_2, \ldots , a_{c_i} + d_i, \ldots , a_k), where 1cik1 \le c_i \le k and di{1,1}d_i \in \{-1, 1\}. 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 nn, if Xiao C is still inside the area, he returns to step 11 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 PP days, how many WeChat steps has he farmed in total. Please help him compute it.

Input Format

The first line contains two integers n,kn, k 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 kk integers wiw_i separated by a single space, representing the size of the area.
The next nn lines each contain two integers ci,dic_i, d_i 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 109+7{10}^9 + 7.
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 1-1.

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 (1,1)(1, 1) he will walk 22 steps; starting from (1,2)(1, 2) he will walk 44 steps; starting from (1,3)(1, 3) he will walk 44 steps.
Starting from (2,1)(2, 1) he will walk 22 steps; starting from (2,2)(2, 2) he will walk 33 steps; starting from (2,3)(2, 3) he will walk 33 steps.
Starting from (3,1)(3, 1) he will walk 11 step; starting from (3,2)(3, 2) he will walk 11 step; starting from (3,3)(3, 3) he will walk 11 step.
In total, 2121 steps.

[Constraints]

Test Point ID nn \le kk \le wiw_i \le
131 \sim 3 55 33
464 \sim 6 100100 33 1010
787 \sim 8 105{10}^5 11 105{10}^5
9129 \sim 12 22 106{10}^6
131613 \sim 16 5×1055 \times {10}^5 1010
172017 \sim 20 33 109{10}^9

For all test points, it is guaranteed that 1n5×1051 \le n \le 5 \times {10}^5, 1k101 \le k \le 10, 1wi1091 \le w_i \le {10}^9, and di{1,1}d_i \in \{-1, 1\}.

Translated by ChatGPT 5