luogu#P4924. [1007] 魔法少女小Scarlet
[1007] 魔法少女小Scarlet
Problem Description
Scarlet has recently learned an array magic. On an 2D array, she can rotate an odd-order square submatrix by clockwise or counterclockwise.
First, Scarlet fills the initial 2D array with the positive integers from to in order from left to right and from top to bottom, and then she casts some simple magic.
Scarlet does not know any block decomposition tricks, nor any Splay-on-Splay. She now gives you the order in which she performs her magic, and she wants you to tell her what the 2D array looks like after all the operations are performed in order.
Input Format
The first line contains two integers , representing the size of the square matrix and the number of magic operations.
The next lines each contain integers , meaning that in this operation, Scarlet rotates the -order matrix centered at row , column by in a certain direction, where means clockwise and means counterclockwise.
Output Format
Output lines, each containing numbers separated by spaces, representing the final matrix.
5 4
2 2 1 0
3 3 1 1
4 4 1 0
3 3 2 1
5 10 3 18 15
4 19 8 17 20
1 14 23 24 25
6 9 2 7 22
11 12 13 16 21
Hint
For of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5