记录编号 39179 评测结果 AAAAAAAAAA
题目名称 绘画 最终得分 100
用户昵称 Gravatarfuhao 是否通过 通过
代码语言 Pascal 运行时间 4.070 s
提交时间 2012-07-05 17:57:22 内存使用 10.51 MiB
显示代码纯文本
const maxm=100001; maxn=1002;
var
 x1,x2,y1,y2,tot,now,x,color,kx,ky,num,n,k,m,i,l,j:longint;
 s,ss:string;
 nextt:array[0..maxn,0..maxn] of longint;
 a,next,c:array[0..maxm] of longint;
 map:array[0..maxn,0..maxn] of longint;
 xx,yy:array[0..maxm,1..2] of longint;
 procedure init;
 begin
  readln(color,x1,y1,x2,y2);
  inc(tot); next[tot]:=a[now];
  a[now]:=tot; c[tot]:=color;
  xx[tot,1]:=x1; xx[tot,2]:=x2;
  yy[tot,1]:=y1; yy[tot,2]:=y2;
 end;
 procedure save;
 begin inc(now); a[now]:=a[now-1]; end;
 procedure load;
 var x:longint;
 begin readln(x); a[now]:=a[x]; end;
 function sn(k:longint):longint;
 begin
  if nextt[j,k]<>k then nextt[j,k]:=sn(nextt[j,k])
   else exit(k);
  sn:=nextt[j,k];
 end;
 procedure paint;
 begin
  for i:=0 to n+2 do
   for j:=0 to n+2 do
    nextt[i,j]:=j;
  i:=a[now];
  while i<>0 do
   begin
    for j:=xx[i,1] to xx[i,2] do
     if (j-xx[i,1]) mod 2=0 then
      begin
       k:=yy[i,1];
       k:=sn(k);
       repeat
        while (k<=yy[i,2]) and (map[j,k]<>1) do k:=nextt[j,k];
        if k<=yy[i,2] then
         begin
          map[j,k]:=c[i];
          nextt[j,k]:=sn(k+2);
          inc(num);
          if num=n*n then exit;
         end;
       until k>yy[i,2];
      end else
      begin
       k:=yy[i,1]+1;
       k:=sn(k);
       repeat
        while (k<=yy[i,2]) and (map[j,k]<>1) do k:=nextt[j,k];
        if k<=yy[i,2] then
         begin
          map[j,k]:=c[i];
          nextt[j,k]:=sn(k+2);
          inc(num);
          if num=n*n then exit;
         end;
       until k>yy[i,2];
      end;
    i:=next[i];
   end;
 end;
 procedure print;
 var i,j:longint;
 begin
  for i:=0 to n-1 do
   begin
    for j:=0 to n-2 do write(map[i,j],' ');
    writeln(map[i,n-1]);
   end;
 end;
begin
 assign(input,'drawing.in'); reset(input);
 assign(output,'drawing.out'); rewrite(output);
 readln(n,k,m); now:=1;
 for i:=0 to n-1 do
  for l:=0 to n-1 do map[i,l]:=1;
 for i:=1 to m do
  begin
   l:=0;
   repeat
    inc(l);
    read(s[l]);
    if s[l]='S' then
     begin
      readln(ss);
      save;
      break;
     end;
   until s[l]=' ';
   s[0]:=chr(l-1);
   if s='PAINT' then init;
   if s='LOAD' then load;
  end;
 paint;
 print;
 close(input); close(output);
end.