# AT2166 Rotate 3x3

### 传送门

\begin{align} &abcde\\ &CBAde\\ &CBEDa\\ &ebcDa\\ &ebAdC\\ &aBEdC\\ &aBcDe----偶数列取反\\ &adCbe\\ &cDAbe\\ &cBade\\ &AbCde----奇数列取反\\ \end{align}

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;bool flag;
int n,m,x[maxn*4],y[maxn*4],z[maxn*4],mp[4][maxn];
int f[maxn*4],w[maxn*4],tot,ans,ans1,s[2],ss[2];
#define lowbit(i) (i&(-i))
int get(int x){int ans=0;for(rg int i=x;i;i-=lowbit(i))ans+=f[i];return ans;}
int main(){
for(rg int i=1;i<=n;i++)
for(rg int j=1;j<=m;j++)
x[i+3*j-3]=i&1,y[i+3*j-3]=j&1,z[i+3*j-3]=j;
for(rg int i=1;i<=n;i++)
for(rg int j=1;j<=m;j++){
int u=1+z[mp[i][j]]*3-3,v=2+z[mp[i][j]]*3-3,w=3+z[mp[i][j]]*3-3;
bool ok1=0,ok2=0,ok3=0;
if(mp[1][j]==u||mp[2][j]==u||mp[3][j]==u)ok1=1;
if(mp[1][j]==v||mp[2][j]==v||mp[3][j]==v)ok2=1;
if(mp[1][j]==w||mp[2][j]==w||mp[3][j]==w)ok3=1;
if(!(ok1&ok2&ok3))flag=1;
if(((i&1)^x[mp[i][j]])||((j&1)^y[mp[i][j]]))flag=1;
}
if(flag){printf("No\n");return 0;}
for(rg int i=1;i<=m;i+=2)if(mp[1][i]!=1+3*z[mp[1][i]]-3)s[1]^=1;
for(rg int i=2;i<=m;i+=2)if(mp[1][i]!=1+3*z[mp[1][i]]-3)s[0]^=1;
for(rg int i=1;i<=m;i+=2)w[++tot]=z[mp[1][i]];