比赛 20110725 评测结果 AAAAAAAATT
题目名称 失落的猴子 最终得分 80
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-25 10:36:58
显示代码纯文本
var
  n,m,k,total,l,i,a,b,c,d,j:longint;
  g:array[0..1000,0..1000]of longint;
  one,two,three,four,first,second,third,fourth,color:array[0..2000000]of longint;

procedure build(t,x1,y1,x2,y2:longint);
var
  midx,midy:longint;
begin
  one[t]:=x1;
  two[t]:=y1;
  three[t]:=x2;
  four[t]:=y2;
  color[t]:=-1;
  if (x1=x2)and(y1=y2) then exit;
  midx:=(x1+x2) div 2;
  midy:=(y1+y2) div 2;

  inc(total);
  first[t]:=total;
  build(total,x1,y1,midx,midy);

  if y1<>y2 then
  begin
    inc(total);
    second[t]:=total;
    build(total,x1,midy+1,midx,y2);
  end;

  if x1<>x2 then
  begin
    inc(total);
    third[t]:=total;
    build(total,midx+1,y1,x2,midy);
  end;

  if (x1<>x2)and(y1<>y2) then
  begin
    inc(total);
    fourth[t]:=total;
    build(total,midx+1,midy+1,x2,y2);
  end;
end;

procedure downpage(t:longint);
begin
  if first[t]<>0 then
  color[first[t]]:=color[t];

  if second[t]<>0 then
  color[second[t]]:=color[t];

  if third[t]<>0 then
  color[third[t]]:=color[t];

  if fourth[t]<>0 then
  color[fourth[t]]:=color[t];

  color[t]:=-1;
end;

procedure change(t,x1,y1,x2,y2:longint);
var
  mx,my:longint;
begin
  if (one[t]=x1)and(two[t]=y1)and(three[t]=x2)and(four[t]=y2) then
  begin
    color[t]:=l;
    exit;
  end;
  if color[t]<>-1 then downpage(t);

  mx:=(one[t]+three[t]) div 2;
  my:=(two[t]+four[t]) div 2;
  if (x2<=mx)and(y2<=my) then change(first[t],x1,y1,x2,y2)
  else if (x2<=mx)and(y1>my) then change(second[t],x1,y1,x2,y2)
  else if (x1>mx)and(y2<=my) then change(third[t],x1,y1,x2,y2)
  else if (x1>mx)and(y1>my) then change(fourth[t],x1,y1,x2,y2)
  else if x2<=mx then
  begin
    change(first[t],x1,y1,x2,my);
    change(second[t],x1,my+1,x2,y2);
  end
  else if y1>my then
  begin
    change(second[t],x1,y1,mx,y2);
    change(fourth[t],mx+1,y1,x2,y2);
  end
  else if x1>mx then
  begin
    change(third[t],x1,y1,x2,my);
    change(fourth[t],x1,my+1,x2,y2);
  end
  else if y2<=my then
  begin
    change(first[t],x1,y1,mx,y2);
    change(third[t],mx+1,y1,x2,y2);
  end
  else begin
    change(first[t],x1,y1,mx,my);
    change(second[t],x1,my+1,mx,y2);
    change(third[t],mx+1,y1,x2,my);
    change(fourth[t],mx+1,my+1,x2,y2);
  end;
end;

procedure down(t:longint);
begin
  if (one[t]=three[t])and(two[t]=four[t]) then
  begin
    g[one[t],two[t]]:=color[t];
    exit;
  end;
  if color[t]<>-1 then downpage(t);
  if first[t]<>0 then down(first[t]);
  if second[t]<>0 then down(second[t]);
  if third[t]<>0 then down(third[t]);
  if fourth[t]<>0 then down(fourth[t]);
end;

begin
  assign(input,'lostmonkey.in'); reset(input);
  assign(output,'lostmonkey.out'); rewrite(output);
  readln(n,m,k);
  total:=1;
  build(1,1,1,n,m);
  color[1]:=0;
  for i:=1 to k do
  begin
    readln(a,b,c,d,l);
    change(1,a,b,c,d);
  end;
  down(1);
  for i:=1 to n do
  begin
   for j:=1 to m do
   write(g[i,j]);
   writeln;
  end;
  close(input);
  close(output);
end.