维护$n^{2}$个三元组$(x,y,z)$,每一个三元组描述$a_{x,y}=z$
对于RLDU这四个操作,即将所有三元组的$x$或$y$执行$pm 1$(模$n$意义下)
对于IC这两个操作,即分别将$y$和$z$交换或$x$和$z$交换
维护这三个元素交换的顺序以及每一个元素加减的量,最终再$o(n^{2})$解出即可
时间复杂度为$o(n^{2}+m)$,可以通过
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define N 1005 4 #define M 100005 5 int t,n,m,num[11],p[3],d[3],b[3],a[N][N],ans[N][N]; 6 char s[M]; 7 int read(){ 8 int x=0; 9 char c=getchar(); 10 while ((c<'0')||(c>'9'))c=getchar(); 11 while ((c>='0')&&(c<='9')){ 12 x=x*10+c-'0'; 13 c=getchar(); 14 } 15 return x; 16 } 17 void write(int x,char c='