年轻人,要和我签订契约,成为 魔法少女 CS大神吗?

挺锻炼耐心的一道题。
题目描述
Scarlet 最近学会了一个数组魔法,她会在 $n\times n$ 二维数组上将一个奇数阶方阵按照顺时针或者逆时针旋转 $90^\circ$。
首先,Scarlet 会把 $1$ 到 $n^2$ 的正整数按照从左往右,从上至下的顺序填入初始的二维数组中,然后她会施放一些简易的魔法。
Scarlet 既不会什么分块特技,也不会什么 Splay 套 Splay,她现在提供给你她的魔法执行顺序,想让你来告诉她魔法按次执行完毕后的二维数组。
输入格式
第一行两个整数 $n,m$,表示方阵大小和魔法施放次数。
接下来 $m$ 行,每行 $4$ 个整数 $x,y,r,z$,表示在这次魔法中,Scarlet 会把以第 $x$ 行第 $y$ 列为中心的 $2r+1$ 阶矩阵按照某种时针方向旋转,其中 $z=0$ 表示顺时针,$z=1$ 表示逆时针。
输出格式
输出 $n$ 行,每行 $n$ 个用空格隔开的数,表示最终所得的矩阵
样例 #1
样例输入 #1
5 4
2 2 1 0
3 3 1 1
4 4 1 0
3 3 2 1
样例输出 #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
提示
对于50%的数据,满足 $r=1$
对于100%的数据 $1\leq n,m\leq500$,满足 $1\leq x-r\leq x+r\leq n,1\leq y-r\leq y+r\leq n$。
代码
// Problem: P4924 [1007]魔法少女小Scarlet
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P4924
// Memory Limit: 125 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
// https://www.luogu.com.cn/record/88875099
// https://www.luogu.com.cn/record/88877110
// https://www.luogu.com.cn/record/88878988
#include<iostream>
using namespace std;
int main(){
int n,m,p[501][501],nn=0;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int o=1;o<=n;o++){
p[i][o]=++nn;
}
}
for(int i=1;i<=m;i++){
int a,b,c,d;
cin>>a>>b>>c>>d; //请注意:输入顺序是先输入中心点纵坐标,后输入中心点横坐标
//而非一般而言的先输入横坐标后输入纵坐标!
int tmp[2*c+1][2*c+1],ly=a-c,lx=b-c;
for(int x=a-c;x<=a+c;x++){
for(int o=b-c;o<=b+c;o++){
if(x<1&&o<1&&x>n&&o>n){
continue;
}
if(d==0){
tmp[o-lx][2*c-(x-ly)]=p[x][o];
}else if(d==1){
tmp[2*c-(o-lx)][x-ly]=p[x][o];
}
}
}
for(int x=a-c;x<=a+c;x++){
for(int o=b-c;o<=b+c;o++){
if(x<1&&o<1&&x>n&&o>n){
continue;
}
p[x][o]=tmp[x-ly][o-lx];
}
}
}
for(int i=1;i<=n;i++){
for(int o=1;o<=n;o++){
cout<<p[i][o]<<" ";
}
cout<<endl;
}
return 0;
}