| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 6 초 | 1024 MB | 5 | 2 | 2 | 40.000% |
We have a sufficiently large $2$-dimensional grid of cells. The grid is paved with square cells from the top to the bottom and from the left to the right.
There is a cell, which is the origin of the coordinates. Let $(x, y)$ denote the cell one arrives at when one moves from the origin to the right direction for the distance of $x$ cells and to the upward direction for the distance of $y$ cells. Here, the left direction for the distance of $a$ cells means the right direction for the distance of $-a$ cells. Similarly, the downward direction for the distance of $a$ cells means the upward direction for the distance of $-a$ cells.
At time $0$, the cells $(X_1, Y_1), (X_2, Y_2), \dots , (X_N, Y_N)$ are black, and all of the other cells are white.
For $t = 0, 1, 2, \dots$, the colors of the cells at time $t + 1$ are determined by the colors of the cells at time $t$ in the following way.
You have $Q$ queries. For the $j$-th ($1 ≤ j ≤ Q$) query, you should answer the number of black cells at time $T_j$.
Write a program which, given the information of the colors of the cells at time 0 and queries, answers the queries.
Read the following data from the standard input.
$N$ $Q$
$X_1$ $Y_1$
$X_2$ $Y_2$
$\vdots$
$X_N$ $Y_N$
$T_1$
$T_2$
$\vdots$
$T_Q$
Write $Q$ lines to the standard output. The $j$-th line should contain the number of black cells at time $T_j$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 4 | $|X_i | ≤ 50$ ($1 ≤ i ≤ N$), $|Y_i | ≤ 50$ ($1 ≤ i ≤ N$), $T_j ≤ 50$ ($1 ≤ j ≤ Q$). |
| 2 | 12 | $|X_i | ≤ 1\,000$ ($1 ≤ i ≤ N$), $|Y_i | ≤ 1\,000$ ($1 ≤ i ≤ N$), $T_j ≤ 1\,000$ ($1 ≤ j ≤ Q$). |
| 3 | 8 | $X_i = Y_i$ ($1 ≤ i ≤ N$), $Q = 1$. |
| 4 | 8 | $X_i = Y_i$ ($1 ≤ i ≤ N$). |
| 5 | 17 | $N ≤ 2\,000$, $Q = 1$. |
| 6 | 25 | $N ≤ 2\,000$. |
| 7 | 26 | No additional constraints. |
2 3 0 2 1 0 0 1 2
2 8 12
The following figure shows the colors of the cells at time $0$. Since there are $2$ black cells, the answer to the first query is $2$.
The following figure shows the colors of the cells at time $1$. Since there are $8$ black cells, the answer to the second query is $8$.
The following figure shows the colors of the cells at time $2$. Since there are $12$ black cells, the answer to the third query is $12$.
This sample input satisfies the constraints of Subtasks 1, 2, 6, 7.
3 5 0 0 2 2 5 5 0 1 2 3 4
3 12 21 24 26
This sample input satisfies the constraints of Subtasks 1, 2, 4, 6, 7.
4 10 -3 -3 3 3 -4 4 4 -4 0 1 2 3 4 5 6 7 8 9
4 16 32 48 56 56 55 56 60 64
This sample input satisfies the constraints of Subtasks 1, 2, 6, 7.