Submission #1774116
Source Code Expand
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // _oo0oo_ // // o8888888o // // 88" . "88 ------ hzt1 // // (| -_- |) // // 0\ = /0 // // ___/`---'\___ // // .' \| |// '. // // / \||| : |||// \ // // / _||||| -:- |||||- \ // // | | \ - /// | | // // | \_| ''\---/'' |_/ | // // \ .-\__ '-' ___/-. / // // ___'. .' /--.--\ `. .'___ // // ."" '< `.___\_<|>_/___.' >' "". // // | | : `- \`.;`\ _ /`;.`/ - ` : | | // // \ \ `_. \_ __\ /__ _/ .-` / / // // =====`-.____`.___ \_____/___.-`___.-'===== // // `=---=' // // // // // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // // // God-He Bless All. // // This Code Will Never Explode. // // // // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #include<vector> #define pb push_back #define mp make_pair #define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++) #define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--) using namespace std; const int Size=1<<16; char buffer[Size],*head,*tail; inline char Getchar() { if(head==tail) { int l=fread(buffer,1,Size,stdin); tail=(head=buffer)+l; } if(head==tail) return -1; return *head++; } inline int read() { int x=0,f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') f=-1; for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f; } #define lc ch[x][0] #define rc ch[x][1] typedef long long ll; typedef pair<int,int> pii; const int maxn=100010; int n,A[4][maxn],B[maxn]; void GG() {puts("No");exit(0);} int pre[maxn],ch[maxn][2],val[maxn],flip[maxn],sumv[maxn]; int ToT; int newnode(int x) {val[++ToT]=x;sumv[ToT]=1;return ToT;} void maintain(int x) {sumv[x]=sumv[lc]+sumv[rc]+1;} void pushdown(int x) { if(flip[x]) { flip[lc]^=1;flip[rc]^=1; val[lc]*=-1;val[rc]*=-1; flip[x]=0; } } void rotate(int x) { int y=pre[x],z=pre[y],d=ch[y][0]==x; ch[y][d^1]=ch[x][d];pre[ch[x][d]]=y; ch[z][ch[z][1]==y]=x;pre[x]=z; ch[x][d]=y;pre[y]=x;maintain(y); } int st[maxn]; void splay(int x) { int top=0; for(int i=x;i;i=pre[i]) st[++top]=i; while(top) pushdown(st[top--]); while(pre[x]) { int y=pre[x],z=pre[y]; if(z) { if(ch[y][0]==x^ch[z][0]==y) rotate(x); else rotate(y); } rotate(x); } maintain(x); } int find(int x,int k) { if(k<=sumv[lc]) return find(lc,k); if(k==sumv[lc]+1) return x; return find(rc,k-(sumv[lc]+1)); } int merge(int x,int y) { if(!sumv[x]&&!sumv[y]) return 0; if(!sumv[x]) return y; if(!sumv[y]) return x; while(ch[x][1]) x=ch[x][1];splay(x); ch[x][1]=y;pre[y]=x; maintain(x);return x; } void split(int x,int k,int& l,int& r) { // [1,k] & [k+1,r] if(!k) {l=0,r=x;return;} x=find(x,k);splay(x); l=x;r=ch[x][1];pre[r]=0;ch[x][1]=0; maintain(x); } void print(int x) { if(!x) return ; pushdown(x); print(lc); printf("%d ",val[x]); print(rc); } int root[2],rt[maxn]; int main() { n=read(); rep(i,1,3) rep(j,1,n) A[i][j]=read(); rep(i,1,n) { if(A[2][i]*2!=A[1][i]+A[3][i]||abs(A[2][i]-A[1][i])!=1) GG(); if(A[1][i]<A[3][i]) B[i]=A[3][i]/3; else B[i]=-A[1][i]/3; if(abs(B[i])%2!=i%2) GG(); } rep(i,1,n) rt[abs(B[i])]=newnode(B[i]); rep(i,1,n) root[i%2]=merge(root[i%2],rt[abs(B[i])]); int cur1=0,cur2=0; rep(i,1,n) { int l,r,mid,p;splay(rt[i]);root[i%2]=rt[i]; split(root[i%2],p=sumv[ch[rt[i]][0]],l,mid); split(mid,1,mid,r);val[l]*=-1;flip[l]^=1; root[i%2]=merge(l,r); if(p%2) val[mid]*=-1; B[i]=val[mid]; if(p) { split(root[(i%2)^1],p,l,r); val[l]*=-1;flip[l]^=1; root[(i%2)^1]=merge(l,r); } } rep(i,1,n) if(B[i]<0) { if(i&1) cur1++; else cur2++; } cur1%=2;cur2%=2; puts(cur1||cur2?"No":"Yes"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Rotate 3x3 |
User | wzj52501 |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 4910 Byte |
Status | AC |
Exec Time | 159 ms |
Memory | 4992 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt, 1_70.txt, 1_71.txt, 1_72.txt, 1_73.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 2304 KB |
0_01.txt | AC | 1 ms | 2176 KB |
0_02.txt | AC | 1 ms | 2304 KB |
0_03.txt | AC | 1 ms | 2176 KB |
0_04.txt | AC | 1 ms | 2176 KB |
1_00.txt | AC | 24 ms | 4608 KB |
1_01.txt | AC | 16 ms | 3200 KB |
1_02.txt | AC | 16 ms | 3200 KB |
1_03.txt | AC | 16 ms | 3200 KB |
1_04.txt | AC | 16 ms | 3200 KB |
1_05.txt | AC | 26 ms | 4608 KB |
1_06.txt | AC | 17 ms | 3200 KB |
1_07.txt | AC | 16 ms | 3200 KB |
1_08.txt | AC | 16 ms | 3200 KB |
1_09.txt | AC | 17 ms | 3200 KB |
1_10.txt | AC | 1 ms | 2176 KB |
1_11.txt | AC | 1 ms | 2176 KB |
1_12.txt | AC | 1 ms | 2176 KB |
1_13.txt | AC | 1 ms | 2304 KB |
1_14.txt | AC | 1 ms | 2304 KB |
1_15.txt | AC | 1 ms | 2304 KB |
1_16.txt | AC | 1 ms | 2176 KB |
1_17.txt | AC | 1 ms | 2176 KB |
1_18.txt | AC | 1 ms | 2304 KB |
1_19.txt | AC | 1 ms | 2176 KB |
1_20.txt | AC | 1 ms | 2304 KB |
1_21.txt | AC | 1 ms | 2304 KB |
1_22.txt | AC | 1 ms | 2176 KB |
1_23.txt | AC | 1 ms | 2304 KB |
1_24.txt | AC | 1 ms | 2304 KB |
1_25.txt | AC | 1 ms | 2176 KB |
1_26.txt | AC | 157 ms | 4992 KB |
1_27.txt | AC | 157 ms | 4992 KB |
1_28.txt | AC | 155 ms | 4992 KB |
1_29.txt | AC | 155 ms | 4992 KB |
1_30.txt | AC | 157 ms | 4992 KB |
1_31.txt | AC | 156 ms | 4992 KB |
1_32.txt | AC | 156 ms | 4992 KB |
1_33.txt | AC | 156 ms | 4992 KB |
1_34.txt | AC | 156 ms | 4992 KB |
1_35.txt | AC | 156 ms | 4992 KB |
1_36.txt | AC | 157 ms | 4992 KB |
1_37.txt | AC | 157 ms | 4992 KB |
1_38.txt | AC | 156 ms | 4992 KB |
1_39.txt | AC | 156 ms | 4992 KB |
1_40.txt | AC | 156 ms | 4992 KB |
1_41.txt | AC | 155 ms | 4992 KB |
1_42.txt | AC | 154 ms | 4992 KB |
1_43.txt | AC | 155 ms | 4992 KB |
1_44.txt | AC | 155 ms | 4992 KB |
1_45.txt | AC | 155 ms | 4992 KB |
1_46.txt | AC | 156 ms | 4992 KB |
1_47.txt | AC | 152 ms | 4992 KB |
1_48.txt | AC | 157 ms | 4992 KB |
1_49.txt | AC | 159 ms | 4992 KB |
1_50.txt | AC | 154 ms | 4992 KB |
1_51.txt | AC | 150 ms | 4992 KB |
1_52.txt | AC | 155 ms | 4992 KB |
1_53.txt | AC | 155 ms | 4992 KB |
1_54.txt | AC | 154 ms | 4992 KB |
1_55.txt | AC | 151 ms | 4864 KB |
1_56.txt | AC | 156 ms | 4864 KB |
1_57.txt | AC | 155 ms | 4992 KB |
1_58.txt | AC | 18 ms | 3200 KB |
1_59.txt | AC | 18 ms | 3200 KB |
1_60.txt | AC | 18 ms | 3200 KB |
1_61.txt | AC | 18 ms | 3200 KB |
1_62.txt | AC | 18 ms | 3200 KB |
1_63.txt | AC | 147 ms | 4864 KB |
1_64.txt | AC | 17 ms | 3200 KB |
1_65.txt | AC | 154 ms | 4992 KB |
1_66.txt | AC | 18 ms | 3200 KB |
1_67.txt | AC | 18 ms | 3200 KB |
1_68.txt | AC | 18 ms | 3200 KB |
1_69.txt | AC | 18 ms | 3200 KB |
1_70.txt | AC | 18 ms | 3200 KB |
1_71.txt | AC | 18 ms | 3200 KB |
1_72.txt | AC | 153 ms | 4992 KB |
1_73.txt | AC | 154 ms | 4992 KB |