English · Original
Chinese · Translation
Formal · Original
Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of _n_ rows and _m_ columns and _q_ tasks. Each task is to swap two submatrices of the given matrix.
For each task Vasiliy knows six integers _a__i_, _b__i_, _c__i_, _d__i_, _h__i_, _w__i_, where _a__i_ is the index of the row where the top-left corner of the first rectangle is located, _b__i_ is the index of its column, _c__i_ is the index of the row of the top-left corner of the second rectangle, _d__i_ is the index of its column, _h__i_ is the height of the rectangle and _w__i_ is its width.
It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles **share a side**. However, rectangles are allowed to share an angle.
Vasiliy wants to know how the matrix will look like after all tasks are performed.
## Input
The first line of the input contains three integers _n_, _m_ and _q_ (2 ≤ _n_, _m_ ≤ 1000, 1 ≤ _q_ ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.
Then follow _n_ lines containing _m_ integers _v__i_, _j_ (1 ≤ _v__i_, _j_ ≤ 109) each — initial values of the cells of the matrix.
Each of the following _q_ lines contains six integers _a__i_, _b__i_, _c__i_, _d__i_, _h__i_, _w__i_ (1 ≤ _a__i_, _c__i_, _h__i_ ≤ _n_, 1 ≤ _b__i_, _d__i_, _w__i_ ≤ _m_).
## Output
Print _n_ lines containing _m_ integers each — the resulting matrix.
[samples]
Vasiliy 终于到了工作地点,那里有大量任务等着他。Vasiliy 被给定一个包含 #cf_span[n] 行和 #cf_span[m] 列的矩阵,以及 #cf_span[q] 个任务。每个任务是交换矩阵中的两个子矩阵。
对于每个任务,Vasiliy 知道六个整数 #cf_span[ai]、#cf_span[bi]、#cf_span[ci]、#cf_span[di]、#cf_span[hi]、#cf_span[wi],其中 #cf_span[ai] 是第一个矩形左上角所在的行索引,#cf_span[bi] 是其列索引,#cf_span[ci] 是第二个矩形左上角所在的行索引,#cf_span[di] 是其列索引,#cf_span[hi] 是矩形的高度,#cf_span[wi] 是其宽度。
保证在同一查询中两个矩形不重叠也不相邻,即没有单元格同时属于两个矩形,且属于不同矩形的两个单元格 *不共享一条边*。但允许矩形共享一个角。
Vasiliy 想知道在执行完所有任务后矩阵会变成什么样子。
输入的第一行包含三个整数 #cf_span[n]、#cf_span[m] 和 #cf_span[q](#cf_span[2 ≤ n, m ≤ 1000],#cf_span[1 ≤ q ≤ 10 000])——矩阵的行数、列数以及 Vasiliy 需要执行的任务数量。
接下来是 #cf_span[n] 行,每行包含 #cf_span[m] 个整数 #cf_span[vi, j](#cf_span[1 ≤ vi, j ≤ 10^9])——矩阵单元格的初始值。
接下来的 #cf_span[q] 行每行包含六个整数 #cf_span[ai]、#cf_span[bi]、#cf_span[ci]、#cf_span[di]、#cf_span[hi]、#cf_span[wi](#cf_span[1 ≤ ai, ci, hi ≤ n],#cf_span[1 ≤ bi, di, wi ≤ m])。
请输出 #cf_span[n] 行,每行包含 #cf_span[m] 个整数——最终的矩阵。
## Input
输入的第一行包含三个整数 #cf_span[n]、#cf_span[m] 和 #cf_span[q](#cf_span[2 ≤ n, m ≤ 1000],#cf_span[1 ≤ q ≤ 10 000])——矩阵的行数、列数以及 Vasiliy 需要执行的任务数量。接下来是 #cf_span[n] 行,每行包含 #cf_span[m] 个整数 #cf_span[vi, j](#cf_span[1 ≤ vi, j ≤ 10^9])——矩阵单元格的初始值。接下来的 #cf_span[q] 行每行包含六个整数 #cf_span[ai]、#cf_span[bi]、#cf_span[ci]、#cf_span[di]、#cf_span[hi]、#cf_span[wi](#cf_span[1 ≤ ai, ci, hi ≤ n],#cf_span[1 ≤ bi, di, wi ≤ m])。
## Output
请输出 #cf_span[n] 行,每行包含 #cf_span[m] 个整数——最终的矩阵。
[samples]
**Definitions**
Let $ n, m \in \mathbb{Z}^+ $ denote the dimensions of the matrix.
Let $ M \in \mathbb{Z}^{n \times m} $ be the initial matrix with entries $ M[i][j] $.
Let $ q \in \mathbb{Z}^+ $ be the number of tasks.
For each task $ k \in \{1, \dots, q\} $, define:
- Rectangle $ R_k^{(1)} = \{(i,j) \mid a_k \le i \le a_k + h_k - 1,\; b_k \le j \le b_k + w_k - 1\} $
- Rectangle $ R_k^{(2)} = \{(i,j) \mid c_k \le i \le c_k + h_k - 1,\; d_k \le j \le d_k + w_k - 1\} $
**Constraints**
1. $ 2 \le n, m \le 1000 $
2. $ 1 \le q \le 10{,}000 $
3. $ 1 \le a_k, c_k, h_k \le n $, $ 1 \le b_k, d_k, w_k \le m $
4. $ R_k^{(1)} \cap R_k^{(2)} = \emptyset $ and $ R_k^{(1)} $, $ R_k^{(2)} $ do not share a side (but may share a corner).
**Objective**
For each task $ k $, swap the contents of $ R_k^{(1)} $ and $ R_k^{(2)} $:
$$
\forall (i,j) \in R_k^{(1)},\quad M[i][j] \leftrightarrow M[i + c_k - a_k][j + d_k - b_k]
$$
Apply all $ q $ tasks sequentially to $ M $. Output the final matrix.
API Response (JSON)
{
"problem": {
"name": "E. Working routine",
"description": {
"content": "Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of _n_ rows and _m_ columns and _q_ tasks. Each task is to swap two submatrices",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF706E"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of _n_ rows and _m_ columns and _q_ tasks. Each task is to swap two submatrices...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "Vasiliy 终于到了工作地点,那里有大量任务等着他。Vasiliy 被给定一个包含 #cf_span[n] 行和 #cf_span[m] 列的矩阵,以及 #cf_span[q] 个任务。每个任务是交换矩阵中的两个子矩阵。\n\n对于每个任务,Vasiliy 知道六个整数 #cf_span[ai]、#cf_span[bi]、#cf_span[ci]、#cf_span[di]、#cf_span[hi]...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the dimensions of the matrix. \nLet $ M \\in \\mathbb{Z}^{n \\times m} $ be the initial matrix with entries $ M[i][j] $. \nLet $ q \\in \\mathbb{Z}^+ ...",
"is_translate": false,
"language": "Formal"
}
]
}