시간 제한메모리 제한제출정답맞힌 사람정답 비율
6 초 1024 MB52240.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.

  • If a cell is black at time $t$, then the cell becomes gray at time $t + 1$.
  • If a cell is gray at time $t$, then the cell becomes white at time $t + 1$.
  • A cell which is white at time $t$ becomes black at time $t + 1$ if at least one of the $4$ adjacent cells (i.e. the $4$ cells which share the edges) is black at time $t$. Otherwise, it remains white at time $t + 1$.

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 ≤ N ≤ 100\,000$.
  • $1 ≤ Q ≤ 500\,000$.
  • $|X_i | ≤ 10^9$ ($1 ≤ i ≤ N$).
  • $|Y_i | ≤ 10^9$ ($1 ≤ i ≤ N$).
  • $(X_i , Y_i) \ne (X_j , Y_j)$ ($1 ≤ i < j ≤ N$).
  • $0 ≤ T_j ≤ 10^9$ ($1 ≤ j ≤ Q$).
  • $T_j < T_{j+1}$ ($1 ≤ j ≤ Q - 1$).
  • Given values are all integers.

서브태스크

번호배점제한
14

$|X_i | ≤ 50$ ($1 ≤ i ≤ N$), $|Y_i | ≤ 50$ ($1 ≤ i ≤ N$), $T_j ≤ 50$ ($1 ≤ j ≤ Q$).

212

$|X_i | ≤ 1\,000$ ($1 ≤ i ≤ N$), $|Y_i | ≤ 1\,000$ ($1 ≤ i ≤ N$), $T_j ≤ 1\,000$ ($1 ≤ j ≤ Q$).

38

$X_i = Y_i$ ($1 ≤ i ≤ N$), $Q = 1$.

48

$X_i = Y_i$ ($1 ≤ i ≤ N$).

517

$N ≤ 2\,000$, $Q = 1$.

625

$N ≤ 2\,000$.

726

No additional constraints.

예제 입력 1

2 3
0 2
1 0
0
1
2

예제 출력 1

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.

예제 입력 2

3 5
0 0
2 2
5 5
0
1
2
3
4

예제 출력 2

3
12
21
24
26

This sample input satisfies the constraints of Subtasks 1, 2, 4, 6, 7.

예제 입력 3

4 10
-3 -3
3 3
-4 4
4 -4
0
1
2
3
4
5
6
7
8
9

예제 출력 3

4
16
32
48
56
56
55
56
60
64

This sample input satisfies the constraints of Subtasks 1, 2, 6, 7.

채점 및 기타 정보

  • 예제는 채점하지 않는다.