#P6557. Yesterday Once More
Yesterday Once More
Description
Note: In the statement, all refer to the cell in row and column .
The game map can be seen as an grid. Each cell may contain an obstacle. For each non-obstacle cell, it may contain a person or not; of course, each cell can contain at most one person.
Now, you can place some people on non-obstacle cells. Each person has a direction, which is one of up, down, left, or right. For each person, you can set their attack range, and the range can be any positive integer.
Attack range: the distance a person can attack. If a person is at , facing right, and their range is 3, then the farthest cell they can attack is . Note that a person’s attack cannot pass through obstacles.
Now UM wants to ask: how many ways are there to place people on the whole map such that no two people can attack each other, and the attack ranges of any two people cannot overlap (because that may waste bullets). Since the answer is too large, you need to output the result modulo .
We number the cell in row and column as . For all people, sort them by the number of the cell with the smallest number within their attack range, and then assign IDs to all people in this sorted order. Two placements are considered different if and only if the number of people is different, or there exists a person with the same ID such that among the cells in their attack range, at least one cell number is different.
However, UM thinks this problem is too easy and might be solved by powerful you in two minutes, so he carefully prepared 5 types of queries for you:
- The number of placements after setting cell as an obstacle.
- The number of placements after setting the entire row as obstacles.
- The number of placements after setting the entire column as obstacles.
- The number of placements after setting cells as obstacles.
- The number of placements after setting cells as obstacles.
Note: After each operation, the map will be restored to the initial state.
Input Format
The first line contains two positive integers , with the meaning as described in the statement.
The next lines each contain integers, describing the game map. If the number is , the cell is non-obstacle; if the number is , the cell is an obstacle.
The next line contains an integer , meaning there are queries.
The next lines: the first integer of each line is , meaning the type of this query:
If , it corresponds to the first type of query, followed by two positive integers , with the meaning as described in the statement.
If , they correspond to the second and third types of queries, followed by one integer , with the meaning as described in the statement.
If , they correspond to the fourth and fifth types of queries, followed by three integers , with the meaning as described in the statement.
Output Format
Output a total of lines.
The first line contains one integer, the answer for the initial state.
The next lines each contain one integer, the answer for each query.
Note: Each output should be taken modulo .
3 3
0 1 0
1 1 1
0 1 0
5
1 2 2
2 2
3 1
4 2 1 1
5 2 2 1
7
1
1
5
1
1
4 4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
3
2 4
1 2 2
4 3 2 2
400
60
400
144
Hint
For all queries, it is guaranteed that the input parameters are within the board size.
For of the testdata, it is guaranteed that and .
For another of the testdata, it is guaranteed that .
For another of the testdata, it is guaranteed that only the first type of query exists.
For another of the testdata, it is guaranteed that only the second and third types of queries exist.
For of the testdata, it is guaranteed that , , and the total number of queries of types 1, 4, and 5 does not exceed .
For all testdata, it is guaranteed that in queries of types 4 and 5, is a positive integer.
Translated by ChatGPT 5
京公网安备 11011102002149号