#P10061. [SNOI2024] 矩阵

    ID: 11443 远端评测题 8000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>各省省选2024O2优化陕西

[SNOI2024] 矩阵

题目描述

你要维护一个 n×nn \times n 的矩阵 AA,其中第 ii 行第 jj 列的元素记作 Ai,jA_{i, j}。行和列从 11 开始标号。一开始,有 Ai,j=(i+1)j mod 998244353A_{i, j} = (i + 1)^j \bmod 998244353。

你需要支持 qq 个操作,每个操作是下面两种操作中的一种。

  • 1 x1 y1 x2 y21\ x_1\ y_1\ x_2\ y_2,这里保证 y2−x2=y1−x1y_2 - x_2 = y_1 - x_1。将子矩形 [x1,x2]×[y1,y2][x_1, x_2] \times [y_1, y_2] 逆时针旋转 9090 度。
    • 具体地,令 d=x2−x1+1d = x_2 - x_1 + 1。
    • 首先提取 d×dd \times d 的子矩阵 A′A',对于所有的 i,ji, j(1≤i,j≤d1 \le i, j \le d),令 Ai,j′←Ax1+i−1,y1+j−1A'_{i, j} \gets A_{x_1 + i - 1, y_1 + j - 1}。
    • 然后将 A′A' 旋转,得到一个 d×dd \times d 的子矩阵 B′B',令 Bi,j′←Aj,d−i+1′B'_{i, j} \gets A'_{j, d - i + 1}。
    • 然后将 B′B' 填回到 AA 中,对所有的 i,ji, j(1≤i,j≤d1 \le i, j \le d),令 Ai+x1−1,j+y1−1←Bi,j′A_{i + x_1 - 1, j + y_1 - 1} \gets B'_{i, j}。
  • 2 x1 y1 x2 y2 d2\ x_1\ y_1\ x_2\ y_2\ d。将子矩形 [x1,x2]×[y1,y2][x_1, x_2] \times [y_1, y_2] 内所有的元素加 dd。
    • 具体地,对于每个 ii(x1≤i≤x2x_1 \le i \le x_2)、jj(y1≤j≤y2y_1 \le j \le y_2),令 Ai,j←Ai,j+dA_{i, j} \gets A_{i, j} + d。

你需要在所有操作结束之后,输出这个矩阵。由于输出可能很大,请输出

$$\Biggl( \sum_{i = 1}^{n} \sum_{j = 1}^{n} A_{i, j} \times {12345}^{(i - 1) n + j} \Biggr) \bmod 1000000007$$

的结果。

输入格式

第一行两个整数 n,qn, q 表示矩阵大小和操作个数。
接下来 qq 行,每行若干个数,表示上面的某种操作。

输出格式

输出一个整数,表示答案对 10000000071000000007 取模的结果。

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

提示

【样例 #1 解释】

对于第一个样例,矩阵分别为

$$\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}$$

其中每个旋转操作对应的数字用红色表示,加操作对应的数字用蓝色表示。


【样例 #3】

见附件中 matrix/matrix3.in 与 matrix/matrix3.ans,这个样例满足测试点 5∼65 \sim 6 的条件限制。


【样例 #4】

见附件中 matrix/matrix3.in 与 matrix/matrix3.ans,这个样例满足测试点 9∼109 \sim 10 的条件限制。


【数据范围】

对于所有的数据,保证 1≤n≤30001 \le n \le 3000,1≤q≤30001 \le q \le 3000。
对于每个操作,保证 1≤x1≤x2≤n1 \le x_1 \le x_2 \le n,1≤y1≤y2≤n1 \le y_1 \le y_2 \le n,1≤d≤1091 \le d \le {10}^9。

具体如下:

测试点编号 n≤n \le q≤q \le 特殊性质
11 100100 30003000 无
22 30003000 A
3∼43 \sim 4 20002000 B
5∼65 \sim 6 30003000
7∼87 \sim 8 20002000 无
9∼109 \sim 10 30003000

特殊性质 A:保证没有第一类旋转操作。
特殊性质 B:保证没有第二类加法操作。