CCF T3

记录于 2026.01.18 · Melting_Pot

CCF T3

没什么太特殊的,注意到全局旋转操作复杂度太高,考虑打个懒标记进行局部旋转。(别忘了对翻转标记进行旋转,因为这么一个唐诗问题调了2h我也是神人了)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include<bits/stdc++.h>
using namespace std;
const int N=500,M=5e5+10;
int m,n,tag,nn,mm;
int mov[M];
char ch[N][N];
struct Node{
    int opt,u,vd,Ll,dr,ro;
}op[M];
void Res(int pos){
    for(int t=tag%4;t;t--){
        int teml(op[pos].Ll),temr(op[pos].dr);
        op[pos].Ll=op[pos].u;
        op[pos].dr=op[pos].vd;
        op[pos].vd=n-teml+1;// 反的       
        op[pos].u=n-temr+1;
        op[pos].ro*=-1;
    }
    char buf[20][20];
    memset(buf,0,sizeof(buf));
    for(int i=op[pos].Ll;i<=op[pos].dr;++i){// lie
        for(int j=op[pos].u;j<=op[pos].vd;++j){ //ceng
            buf[j-op[pos].u+1][i-op[pos].Ll+1]=ch[j][i];
        }
    }
    if(~op[pos].ro){// 上下翻转
        int sum=op[pos].u+op[pos].vd;
        for(int i=op[pos].Ll;i<=op[pos].dr;++i){
            for(int j=op[pos].u;j<=op[pos].vd;++j){
                ch[j][i]=buf[sum-j-op[pos].u+1][i-op[pos].Ll+1];
            }
        }
    }else{// 左右翻转 
        int sum=op[pos].Ll+op[pos].dr;
        for(int i=op[pos].u;i<=op[pos].vd;++i){
            for(int j=op[pos].Ll;j<=op[pos].dr;++j){
                ch[i][j]=buf[i-op[pos].u+1][sum-j-op[pos].Ll+1];
            }
        }
    }
}
void Rol(int pos){
    tag+=op[pos].ro;
    for(int t=tag%4;t;t--){
        int temv(op[pos].vd);
        op[pos].vd=op[pos].u;
        op[pos].u=n-temv-op[pos].Ll+2;// 反的
    }
    char buf[20][20];
    memset(buf,0,sizeof(buf));
    for(int i=op[pos].u;i<=op[pos].u+op[pos].Ll-1;++i){
        for(int j=op[pos].vd;j<=op[pos].vd+op[pos].Ll-1;++j){
            int ii=i-op[pos].u+1,jj=j-op[pos].vd+1;
            buf[ii][jj]=ch[i][j];
        }
    }
    if(op[pos].dr==90){
        for(int i=op[pos].u;i<=op[pos].u+op[pos].Ll-1;++i){
            for(int j=op[pos].vd;j<=op[pos].vd+op[pos].Ll-1;++j){
                int ii=i-op[pos].u+1,jj=j-op[pos].vd+1;
                ch[i][j]=buf[jj][op[pos].Ll-ii+1];
            }
        }
    }else if(op[pos].dr==180){
        for(int i=op[pos].u;i<=op[pos].u+op[pos].Ll-1;++i){
            for(int j=op[pos].vd;j<=op[pos].vd+op[pos].Ll-1;++j){
                int ii=i-op[pos].u+1,jj=j-op[pos].vd+1;
                ch[i][j]=buf[op[pos].Ll-ii+1][op[pos].Ll-jj+1];
            }
        }
    }else{
        for(int i=op[pos].u;i<=op[pos].u+op[pos].Ll-1;++i){
            for(int j=op[pos].vd;j<=op[pos].vd+op[pos].Ll-1;++j){
                int ii=i-op[pos].u+1,jj=j-op[pos].vd+1;
                ch[i][j]=buf[op[pos].Ll-jj+1][ii];
            }
        }
    }
}
int main(){
    // freopen("2.in","r",stdin);
    // freopen("2.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n,mm=nn=n;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            cin>>ch[i][j];
        }
    }
    cin>>m;
    for(int i=1;i<=m;++i) cin>>mov[i];
    for(int i=2;i<=m;i+=6){
        op[i/6+1].opt=mov[i];
        op[i/6+1].u=mov[i+1];
        op[i/6+1].vd=mov[i+2];
        op[i/6+1].Ll=mov[i+3];
        op[i/6+1].dr=mov[i+4];
        op[i/6+1].ro=mov[i+5];
    }
    for(int i=mov[1];i;i--){
        if(op[i].opt==2) Res(i);
        else Rol(i);
    }
    char buf_[N][N];
    for(int t=tag%4;t;t--){
        memset(buf_,0,sizeof(buf_));
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                buf_[i][j]=ch[i][j];
            }
        }
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                ch[i][j]=buf_[n-j+1][i];
            }
        }
    }
    for(int j=1;j<=n;++j){
        if(ch[1][j]=='?'){
            mm=j-1;
            break;
        }
    }
    for(int i=1;i<=n;++i){
        if(ch[i][1]=='?'){
            nn=i-1;
            break;
        }
    }
    for(int i=1;i<=nn;++i){
        for(int j=1;j<=mm;++j) cout<<ch[i][j];
        cout<<endl;
    }
}
/* 
3
649
712
583
19
3 1 2 2 2 180 2 2 1 3 2 3 -1 1 2 2 2 90 1
*/