乍一看感觉好神,仔细一看数据范围……
什么水题啊,直接暴力就可以了……
var map,w:array[..,..] of longint;
v:array[..,..] of boolean;
i,j,k,a1,a2,b1,b2,ans,n,m:longint;
go:array[..,..] of longint;
ff:boolean;
ss:char; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; procedure find(x,y:longint);
var i,nx,ny:longint;
begin
w[x,y]:=;
for i:= to do
begin
nx:=x+go[,i];
ny:=y+go[,i];
if v[nx,ny] then continue;
if map[nx,ny]>=map[x,y] then continue;
if w[nx,ny]= then find(nx,ny);
w[x,y]:=max(w[x,y],w[nx,ny]+);
end;
end; begin
readln(n);
for i:= to n do
begin
for j:= to n do
read(map[i,j]);
readln;
end;
for i:= to n+ do
begin
v[,i]:=true;
v[i,]:=true;
v[n+,i]:=true;
v[i,n+]:=true;
end;
go[,]:=-;
go[,]:=;
go[,]:=;
go[,]:=-;
readln(m);
ff:=true;
for k:= to m do
begin
read(ss);
if ss='C' then
begin
readln(a1,b1,a2);
map[a1,b1]:=a2;
ff:=true;
end
else if ss='S' then
begin
readln(a1,b1,a2,b2);
for i:=a1 to a2 do
for j:=b1 to b2 do
v[i,j]:=true;
ff:=true;
end
else if ss='B' then
begin
readln(a1,b1,a2,b2);
for i:=a1 to a2 do
for j:=b1 to b2 do
v[i,j]:=false;
ff:=true;
end
else begin
readln;
if not ff then
begin
writeln(ans);
continue;
end;
for i:= to n do
for j:= to n do w[i,j]:=;
for i:= to n do
for j:= to n do
if (not v[i,j]) and (w[i,j]=) then
find(i,j);
ans:=-maxlongint;
for i:= to n do
for j:= to n do ans:=max(ans,w[i,j]);
writeln(ans);
ff:=false;
end;
end;
end.