比赛 20120705 评测结果 AAAAAAAAAA
题目名称 绘画 最终得分 100
用户昵称 IMSL77 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-05 11:54:17
显示代码纯文本
program main;
type
  integer=longint;
const
  maxn=1100;
  maxm=110000;
var
  n,k,m,tot:integer;
  s:array[1..maxm] of string[30];
  line:array[1..maxm] of integer;
  num:array[0..1] of integer;
  x1,y1,x2,y2,co:array[0..1,1..maxm] of integer;
  col:array[1..maxn,1..maxn] of integer;

  procedure Fopen;
  begin
    assign(input,'drawing.in');
    reset(input);
    assign(output,'drawing.out');
    rewrite(output);
  end;

  procedure Fclose;
  begin
    close(input);
    close(output);
  end;

  procedure Init;
  var
    i:integer;
    l,r,u,d,p,q,c,code:integer;
  begin
    readln(n,k,m);
    tot:=0;
    for i:=1 to m do readln(s[i]);
    for i:=1 to m do if copy(s[i],1,4)='SAVE' then
    begin
      inc(tot);
      line[tot]:=i;
    end;
    num[0]:=0; num[1]:=0;
    i:=m;
    while i>0 do
    begin
      if copy(s[i],1,4)='PAIN' then
      begin
        delete(s[i],1,5);
        while s[i,1]=' ' do delete(s[i],1,1);
        p:=pos(' ',s[i]);
        val(copy(s[i],1,p-1),c,code);
        delete(s[i],1,p);
        while s[i,1]=' ' do delete(s[i],1,1);
        p:=pos(' ',s[i]);
        val(copy(s[i],1,p-1),l,code);
        delete(s[i],1,p);
        while s[i,1]=' ' do delete(s[i],1,1);
        p:=pos(' ',s[i]);
        val(copy(s[i],1,p-1),u,code);
        delete(s[i],1,p);
        while s[i,1]=' ' do delete(s[i],1,1);
        p:=pos(' ',s[i]);
        val(copy(s[i],1,p-1),r,code);
        delete(s[i],1,p);
        while s[i,1]=' ' do delete(s[i],1,1);
        while s[i,length(s[i])]=' ' do delete(s[i],length(s[i]),1);
        val(s[i],d,code);
        q:=((l+1) xor (u+1)) and 1;
        inc(num[q]);
        x1[q,num[q]]:=u+1; y1[q,num[q]]:=l+1;
        x2[q,num[q]]:=d+1; y2[q,num[q]]:=r+1;
        co[q,num[q]]:=c;
      end;
      if copy(s[i],1,4)='LOAD' then
      begin
        delete(s[i],1,4);
        while s[i,1]=' ' do delete(s[i],1,1);
        while s[i,length(s[i])]=' ' do delete(s[i],length(s[i]),1);
        val(s[i],p);
        i:=line[p]-1;
        continue;
      end;
      dec(i);
    end;
  end;

  procedure paint(l,r,u,d,c,q:integer);
  var
    i,j:integer;
  begin
    for i:=l to r do
    for j:=u to d do
      if (i xor j) and 1=q then col[j,i]:=c;
  end;

  procedure up(k,l,r,u,d,c,q:integer);
  begin
    while (k>0) and
          ((l>x2[q,k]) or (r<x1[q,k]) or (u>y2[q,k]) or (d<y1[q,k]))
    do dec(k);
    if k=0 then begin paint(l,r,u,d,c,q); exit; end;
    if l<x1[q,k] then begin up(k-1,l,x1[q,k]-1,u,d,c,q); l:=x1[q,k]; end;
    if r>x2[q,k] then begin up(k-1,x2[q,k]+1,r,u,d,c,q); r:=x2[q,k]; end;
    if u<y1[q,k] then begin up(k-1,l,r,u,y1[q,k]-1,c,q); u:=y1[q,k]; end;
    if d>y2[q,k] then begin up(k-1,l,r,y2[q,k]+1,d,c,q); d:=y2[q,k]; end;
  end;

  procedure Solve;
  var
    i,j:integer;
  begin
    for i:=1 to n do
    for j:=1 to n do
      col[i,j]:=1;
    for i:=1 to num[0] do up(i-1,x1[0,i],x2[0,i],y1[0,i],y2[0,i],co[0,i],0);
    for i:=1 to num[1] do up(i-1,x1[1,i],x2[1,i],y1[1,i],y2[1,i],co[1,i],1);
    for i:=1 to n do
    begin
      for j:=1 to n-1 do write(col[i,j],' ');
      writeln(col[i,n]);
    end;
  end;

begin
  Fopen;
  Init;
  Solve;
  Fclose;
end.