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 denote the cell reached by moving cells to the right from the origin, and then moving cells upward. Here, moving cells to the left means moving cells to the right. Similarly, moving cells downward means moving cells upward.
At time , the cells are black, and all other cells are white.
For , based on the colors of the cells at time , the colors at time are determined as follows:
- If a cell is black at time , then at time this cell becomes gray.
- If a cell is gray at time , then at time this cell becomes white.
- If a cell is white at time , and among its four adjacent cells (i.e., the four cells sharing an edge with it) at least one is black at time , then at time this cell becomes black. Otherwise, it remains white at time .
You have queries. For the -th query, you should answer how many black cells there are at time .
Given the initial cell colors at time and the queries, write a program to answer the queries.
Input Format
The first line contains two integers .
The next lines each contain two integers .
The next lines each contain one integer .
Output Format
Output lines, each containing one integer, representing the number of black cells at time .
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 . Since there are black cells, the answer to the first query is .

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

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

This sample satisfies the constraints of subtasks .
[Sample Explanation #2]
This sample satisfies the constraints of subtasks .
[Sample Explanation #3]
This sample satisfies the constraints of subtasks .
[Constraints]
For all testdata, the following hold:
The additional constraints and scores for the subtasks are shown in the table below.
| Subtask | Additional Constraints | Score |
|---|---|---|
| $\lvert X_i\rvert ,\lvert Y_i\rvert \le 50,T_j\le 50$ | ||
| $\lvert X_i\rvert ,\lvert Y_i\rvert \le 1\ 000,T_j\le 1\ 000$ | ||
| No additional constraints |
Translated by ChatGPT 5