对于每个操作,直接暴力做就行了,询问的话搜一遍,然后
就这么水过去了。
/************************************************************** Problem: 3208 User: BLADEVIL Language: Pascal Result: Accepted Time:17276 ms Memory:9032 kb ****************************************************************/ //By BLADEVIL var n, m :longint; map, w :array[0..1000,0..1000] of longint; flag :array[0..1000,0..1000] of boolean; ans :longint; go :array[0..2,0..4] of longint; function max(a,b:longint):longint; begin if a>b then max:=a else max:=b; end; procedure find(x,y:longint); var i :longint; nx, ny :longint; begin for i:=1 to 4 do begin nx:=x+go[1,i]; ny:=y+go[2,i]; if flag[nx,ny] then continue; if map[nx,ny]>=map[x,y] then continue; if w[nx,ny]=1 then find(nx,ny); w[x,y]:=max(w[x,y],w[nx,ny]+1); end; end; procedure init; var i, j :longint; begin read(n); for i:=1 to n do for j:=1 to n do read(map[i,j]); fillchar(flag,sizeof(flag),false); for i:=0 to n+1 do begin flag[0,i]:=true; flag[i,0]:=true; flag[n+1,i]:=true; flag[i,n+1]:=true; end; go[1,1]:=-1; go[2,2]:=1; go[1,3]:=1; go[2,4]:=-1; end; procedure main; var i, j, t :longint; ss :char; x, y, z :longint; a1, b1, a2, b2 :longint; begin readln(m); for t:=1 to m do begin read(ss); if ss='C' then begin readln(x,y,z); map[x,y]:=z; end else if ss='S' then begin readln(a1,b1,a2,b2); for i:=a1 to a2 do for j:=b1 to b2 do flag[i,j]:=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 flag[i,j]:=false; end else begin readln; for i:=1 to n do for j:=1 to n do w[i,j]:=1; for i:=1 to n do for j:=1 to n do if (not flag[i,j]) and (w[i,j]=1) then find(i,j); ans:=-maxlongint; for i:=1 to n do for j:=1 to n do ans:=max(ans,w[i,j]); writeln(ans); end; end; end; begin init; main; end.