比赛 ZLXOI2015Day1 评测结果 AWWWWWWWWW
题目名称 虐狗大赛 最终得分 10
用户昵称 ywx 运行时间 0.304 s
代码语言 Pascal 内存使用 1.69 MiB
提交时间 2015-10-29 10:42:51
显示代码纯文本
type xg=^data;
     data=record
     zhi,qz:longint;
     next:xg;
     end;
var i,j,n,cc,y,k,q,cs,qq:longint;
    d,h:array[0..100010] of longint;
    x,last:array[0..100010] of xg;
    p:xg;
begin
  assign(input,'thebigmatch.in');
  assign(output,'thebigmatch.out');
  reset(input);
  rewrite(output);
  readln(n);
  for i:=1 to n do
  read(h[i]);
  for i:=1 to n do
  read(d[i]);

  fillchar(x,sizeof(x),0);

  readln(q);
  for y:=1 to q do
  begin
    read(cc);
    if cc=0 then begin readln(i,j,k);
                new(p);p^.zhi:=k;p^.qz:=1;p^.next:=nil;
                if x[i]=nil then begin x[i]:=p;last[i]:=p;end
                  else begin last[i]^.next:=p;last[i]:=p;end;
                new(p);p^.zhi:=k;p^.qz:=2;p^.next:=nil;
                 if x[j]=nil then begin x[j]:=p;last[j]:=p;end
                  else begin last[i]^.next:=p;last[i]:=p;end;
               end;

    if cc=1 then begin qq:=0;cs:=0;
                    for i:=1 to n do
                    begin

                      if x[i]<>nil then begin p:=x[i];
                         if p^.qz=1 then begin inc(cs);qq:=qq+p^.zhi;end;
                      while p^.next<>nil do
                          begin
                             p:=p^.next;
                         if p^.qz=1 then begin inc(cs);qq:=qq+p^.zhi;end;
                          end;
                                        end;

                      h[i]:=h[i]-(qq-d[i]*cs);

                       if x[i]<>nil then begin p:=x[i];
                         if p^.qz=2 then begin dec(cs);qq:=qq-p^.zhi;end;
                      while p^.next<>nil do
                          begin
                             p:=p^.next;
                         if p^.qz=2 then begin dec(cs);qq:=qq-p^.zhi;end;
                          end;
                                        end;

                    end;

                 fillchar(x,sizeof(x),0);
                 for  i:=1 to n do
                 write(h[i],' ');
                 writeln;
              end;

     end;

     close(input);
     close(output);
end.