#P10061. [SNOI2024] 矩阵
[SNOI2024] 矩阵
Problem Description
You need to maintain an matrix , where the element in row and column is denoted as . Rows and columns are indexed starting from . Initially, .
You need to support operations. Each operation is one of the following two types.
- , where it is guaranteed that . Rotate the sub-rectangle by degrees counterclockwise.
- Specifically, let .
- First, extract a submatrix . For all (), set .
- Then rotate to obtain a submatrix , and set .
- Then write back into . For all (), set .
- . Add to all elements in the sub-rectangle .
- Specifically, for each () and (), set .
After all operations are finished, output this matrix. Since the output can be very large, please output the value of
$$\Biggl( \sum_{i = 1}^{n} \sum_{j = 1}^{n} A_{i, j} \times {12345}^{(i - 1) n + j} \Biggr) \bmod 1000000007$$instead.
Input Format
The first line contains two integers , representing the matrix size and the number of operations.
The next lines each contain several numbers, describing one of the operations above.
Output Format
Output one integer, representing the answer modulo .
4 4
1 1 2 3 4
2 2 1 4 2 3
1 2 1 3 2
2 1 1 1 4 5
984660761
10 10
2 5 1 10 4 689412516
1 3 4 3 4
1 3 5 4 6
1 4 1 8 5
1 1 2 1 2
1 4 2 7 5
1 2 5 2 5
2 3 3 3 9 856075030
2 4 2 5 6 308750020
2 1 5 9 7 252732904
94292030
Hint
[Sample #1 Explanation]
For the first sample, the matrix is respectively
$$\begin{bmatrix} 2 & {\textcolor{red}{4}} & {\textcolor{red}{8}} & {\textcolor{red}{16}} \\ 3 & {\textcolor{red}{9}} & {\textcolor{red}{27}} & {\textcolor{red}{81}} \\ 4 & {\textcolor{red}{16}} & {\textcolor{red}{64}} & {\textcolor{red}{256}} \\ 5 & 25 & 125 & 625 \end{bmatrix} \to \begin{bmatrix} 2 & 16 & 81 & 256 \\ {\textcolor{blue}{3}} & {\textcolor{blue}{8}} & 27 & 64 \\ {\textcolor{blue}{4}} & {\textcolor{blue}{4}} & 9 & 16 \\ {\textcolor{blue}{5}} & {\textcolor{blue}{25}} & 125 & 625 \end{bmatrix} \to \begin{bmatrix} 2 & 16 & 81 & 256 \\ {\textcolor{red}{6}} & {\textcolor{red}{11}} & 27 & 64 \\ {\textcolor{red}{7}} & {\textcolor{red}{7}} & 9 & 16 \\ 8 & 28 & 125 & 625 \end{bmatrix}$$$$\to \begin{bmatrix} {\textcolor{blue}{2}} & {\textcolor{blue}{16}} & {\textcolor{blue}{81}} & {\textcolor{blue}{256}} \\ 11 & 7 & 27 & 64 \\ 6 & 7 & 9 & 16 \\ 8 & 28 & 125 & 625 \end{bmatrix} \to \begin{bmatrix} 7 & 21 & 86 & 261 \\ 11 & 7 & 27 & 64 \\ 6 & 7 & 9 & 16 \\ 8 & 28 & 125 & 625 \end{bmatrix}$$The numbers corresponding to each rotation operation are marked in red, and the numbers corresponding to each addition operation are marked in blue.
[Sample #3]
See the attachments matrix/matrix3.in and matrix/matrix3.ans. This sample satisfies the constraints of test points .
[Sample #4]
See the attachments matrix/matrix3.in and matrix/matrix3.ans. This sample satisfies the constraints of test points .
[Constraints]
For all testdata, it is guaranteed that and .
For each operation, it is guaranteed that , , and .
Details are as follows:
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| A | |||
| B | |||
| None | |||
Special property A: It is guaranteed that there are no type 1 rotation operations.
Special property B: It is guaranteed that there are no type 2 addition operations.
Translated by ChatGPT 5