傻逼的世界题目+题解

一道我自己出的水题,题目描述:
要求支持两种操作:对一个三维区间上的数都加上一个数,或者询问一个三维区间上所有数的和,三维区间的三个坐标都是整数且范围在[1,100],询问10000个。
写个三维树状数组就AC了,是不是很简单。数据:
sbworld
标程:

var
  c1,c2,c3,c4,c5,c6,c7,c8:array[1..105,1..105,1..105]of int64;
  num,x1,y1,z1,x2,y2,z2,n,m,p:longint; v,s1,s2:int64;
  function lowbit(x:longint):longint;
  begin exit(x and(-x)); end;
  procedure add(x,y,z:longint;v:int64);
  var
    i,j,k,tx,ty,tz:longint;
  begin
    tx:=x; ty:=y; tz:=z;
    i:=x;
    while i<=n do
    begin
      j:=y;
      while j<=m do
      begin
        k:=z;
        while k<=p do
        begin
          inc(c1[i,j,k],v);
          inc(c2[i,j,k],v*tx);
          inc(c3[i,j,k],v*ty);
          inc(c4[i,j,k],v*tz);
          inc(c5[i,j,k],v*ty*tz);
          inc(c6[i,j,k],v*tx*tz);
          inc(c7[i,j,k],v*tx*ty);
          inc(c8[i,j,k],v*tx*ty*tz);
          k:=k+lowbit(k);
        end;
        j:=j+lowbit(j);
      end;
      i:=i+lowbit(i);
    end;
  end;
  function sum(x,y,z:longint):int64;
  var
    i,j,k,tx,ty,tz:longint;
  begin
    sum:=0;
    tx:=x; ty:=y; tz:=z;
    i:=x;
    while i>0 do
    begin
      j:=y;
      while j>0 do
      begin
        k:=z;
        while k>0 do
        begin
          inc(sum,c1[i,j,k]*(tx+1)*(ty+1)*(tz+1));
          dec(sum,c2[i,j,k]*(ty+1)*(tz+1));
          dec(sum,c3[i,j,k]*(tx+1)*(tz+1));
          dec(sum,c4[i,j,k]*(tx+1)*(ty+1));
          inc(sum,c5[i,j,k]*(tx+1));
          inc(sum,c6[i,j,k]*(ty+1));
          inc(sum,c7[i,j,k]*(tz+1));
          dec(sum,c8[i,j,k]);
          k:=k-lowbit(k);
        end;
        j:=j-lowbit(j);
      end;
      i:=i-lowbit(i);
    end;
  end;
begin
  fillchar(c1,sizeof(c1),0);
  fillchar(c2,sizeof(c2),0);
  fillchar(c3,sizeof(c3),0);
  fillchar(c4,sizeof(c4),0);
  fillchar(c5,sizeof(c5),0);
  fillchar(c6,sizeof(c6),0);
  fillchar(c7,sizeof(c7),0);
  fillchar(c8,sizeof(c8),0);
  readln(n,m,p);
  while not eof do
  begin
    read(num);
    case num of
      1:begin
          readln(x1,y1,z1,x2,y2,z2,v);
          add(x1,y1,z1,v); add(x2+1,y1,z1,-v); add(x1,y2+1,z1,-v); add(x1,y1,z2+1,-v);
          add(x2+1,y2+1,z1,v); add(x2+1,y1,z2+1,v); add(x1,y2+1,z2+1,v); add(x2+1,y2+1,z2+1,-v);
        end;
      2:begin
          readln(x1,y1,z1,x2,y2,z2);
          s1:=sum(x2,y2,z2)-sum(x1-1,y2,z2)-sum(x2,y1-1,z2)-sum(x2,y2,z1-1);
          s2:=sum(x1-1,y1-1,z2)+sum(x1-1,y2,z1-1)+sum(x2,y1-1,z1-1)-sum(x1-1,y1-1,z1-1);
          writeln(s1+s2);
        end;
    end;
  end;
end.