luogu#P12018. [NOISG 2025 Finals] Robots
[NOISG 2025 Finals] Robots
题目描述
Funnyland is modelled as a grid of size . The rows of the grid are numbered to from top to bottom, and the columns of the grid are numbered to from left to right. We refer to the cell located at row r and column c of the grid as cell .
Initially, all cells in this grid are coloured white, except for the rightmost column of cells, which are all coloured black.
The columns to each contain exactly one special cell. Each of these special cells are to be coloured red or blue. The edges of the grid (i.e., the topmost row, the bottommost row, the leftmost column, and the rightmost column) will never contain special cells.
Several robots will be placed on cells in the leftmost column and will move according to the colour of their cell:
- If the cell is white, the robot moves right.
- If the cell is red, the robot moves upward.
- If the cell is blue, the robot moves downward.
- If the cell is black, the robot does not move.
Robots do not collide with each other; each robot moves independently of other robots. Multiple robots are allowed to occupy the same cell.
A query consists of two integers and (). For each , there will be a robot starting at . Across all possible configurations of colouring the special cells red or blue, determine the minimum number of distinct final cells the robots can occupy.
Note that different queries may result in different configurations of colouring the cells red and blue.
输入格式
Your program must read from standard input.
The first line of input contains two space-separated integers and .
The second line of input contains space-separated integers , indicating that the special cells are .
The third line of input contains one integer .
The following lines of input each contain two space-separated integers. The -th of these lines contains and .
输出格式
Your program must print to standard output.
The output should contain lines. The -th of these lines should contain one integer, the answer to the -th query.
4 4
3 2 4 1
3
1 4
1 3
2 4
2
1
1
15 16
5 15 3 4 13 8 3 7 14 6 2 10 11 12 9 1
20
4 10
7 15
5 15
2 6
7 15
5 15
12 15
13 14
5 14
13 14
2 11
3 11
2 5
9 11
3 15
5 14
1 13
3 7
7 12
4 8
2
2
3
2
2
3
1
1
3
1
3
2
1
1
3
3
4
1
2
1
提示
Subtasks
For all test cases, the input will satisfy the following bounds:
- for all
- for all
Your program will be tested on input instances that satisfy the following restrictions:
Subtask | Marks | Additional Constraints |
---|---|---|
Sample test cases | ||
No additional constraints |
Sample Test Case 1 Explanation
This test case is valid for subtasks , and .
The grid is coloured as foll This test case is valid for subtasks , and . ows, with the special cells in violet.
For the first query, we can colour the special cells at and blue, and red to achieve the following:
- The robot starting at moves to , and ends at .
- The robot starting at moves to $(2, 1), (2, 2), (1, 2), (1, 3), (1, 4), (0, 4), (0, 5)$, and ends at .
- The robot starting at moves to , and ends at .
- The robot starting at moves to , and ends at .
The robots end at distinct cells, and , hence the correct output is .
For the second query, we can colour the special cells as follows:
The robots starting at , and all end at .
For the third query, we can colour the special cells as follows:
The robots starting at , and all end at .
Sample Test Case 2 Explanation
This test case is valid for subtasks , and .