luogu#P9513. [JOI Open 2023] 细胞自动机 / Cell Automaton

[JOI Open 2023] 细胞自动机 / Cell Automaton

Background

Translated from JOI Open 2023 T2 「セルオートマトン / Cell Automaton」。

Problem Description

We have a sufficiently large 2D grid, tiled with square cells from top to bottom and from left to right.

One cell is the origin. Let (x,y)(x,y) denote the cell reached by moving xx cells to the right from the origin, and then moving yy cells upward. Here, moving aa cells to the left means moving a-a cells to the right. Similarly, moving aa cells downward means moving a-a cells upward.

At time 00, the cells (X1,Y1),(X2,Y2),,(XN,YN)(X_1,Y_1),(X_2,Y_2),\ldots,(X_N,Y_N) are black, and all other cells are white.

For t=0,1,2,t=0,1,2,\ldots, based on the colors of the cells at time tt, the colors at time t+1t+1 are determined as follows:

  • If a cell is black at time tt, then at time t+1t+1 this cell becomes gray.
  • If a cell is gray at time tt, then at time t+1t+1 this cell becomes white.
  • If a cell is white at time tt, and among its four adjacent cells (i.e., the four cells sharing an edge with it) at least one is black at time tt, then at time t+1t+1 this cell becomes black. Otherwise, it remains white at time t+1t+1.

You have QQ queries. For the jj-th query, you should answer how many black cells there are at time TjT_j.

Given the initial cell colors at time 00 and the queries, write a program to answer the queries.

Input Format

The first line contains two integers N,QN,Q.

The next NN lines each contain two integers Xi,YiX_i,Y_i.

The next QQ lines each contain one integer TjT_j.

Output Format

Output QQ lines, each containing one integer, representing the number of black cells at time TjT_j.

2 3
0 2
1 0
0
1
2

2
8
12

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

3
12
21
24
26

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

Hint

[Sample Explanation #1]

The figure below shows the state of the cells at time 00. Since there are 22 black cells, the answer to the first query is 22.

The figure below shows the state of the cells at time 11. Since there are 88 black cells, the answer to the second query is 88.

The figure below shows the state of the cells at time 22. Since there are 1212 black cells, the answer to the third query is 1212.

This sample satisfies the constraints of subtasks 1,2,6,71,2,6,7.

[Sample Explanation #2]

This sample satisfies the constraints of subtasks 1,2,4,6,71,2,4,6,7.

[Sample Explanation #3]

This sample satisfies the constraints of subtasks 1,2,6,71,2,6,7.

[Constraints]

For all testdata, the following hold:

  • 1N1051\le N\le 10^5
  • 1Q5×1051\le Q\le 5\times 10^5
  • Xi,Yi109|X_i|,|Y_i|\le 10^9
  • (Xi,Yi)(Xj,Yj) (1i<jN)(X_i,Y_i)\neq (X_j,Y_j)\ (1\le i < j\le N)
  • 0Tj1090\le T_j\le 10^9
  • Tj<Tj+1T_j<T_{j+1}

The additional constraints and scores for the subtasks are shown in the table below.

Subtask Additional Constraints Score
11 $\lvert X_i\rvert ,\lvert Y_i\rvert \le 50,T_j\le 50$ 44
22 $\lvert X_i\rvert ,\lvert Y_i\rvert \le 1\ 000,T_j\le 1\ 000$ 1212
33 Xi=Yi,Q=1X_i=Y_i,Q=1 88
44 Xi=YiX_i=Y_i
55 N2 000,Q=1N\le 2\ 000,Q=1 1717
66 N2 000N\le 2\ 000 2525
77 No additional constraints 2626

Translated by ChatGPT 5