• bzoj 3132: 上帝造题的七分钟 (二维树状数组)


    推推公式,最后变成四个东西的前缀和

    然后不知道为什么一直wa,数据在本地测是没有错的&

    好心的管理员还给了某位p党大神a了的代码,感人肺腑(虽然还是没发现到底我的程序是问题)

    var
      f1,f2,f3,f4:array[0..2500,0..2500]of longint;
      x1,y1,x2,y2,n,m,j:longint;
      ch:char;
     
     
     
    function lowbit(x:longint):longint;
    begin
      exit(x and (-x));
    end;
     
    procedure add(x,y,z:longint);
    var
      i,j:longint;
    begin
      if (x=0) or (y=0) then exit;
      i:=x;
      while i<=n do begin
        j:=y;
        while j<=m do begin
          inc(f1[i,j],z);
          inc(f2[i,j],z*y);
          inc(f3[i,j],z*x);
          inc(f4[i,j],z*x*y);
          inc(j,lowbit(j));
        end;
        inc(i,lowbit(i));
      end;
    end;
     
    function askans(x,y:longint):longint;
    var
      ans,i,j:longint;
    begin
      ans:=0;
      i:=x;
      while i>=1 do begin
        j:=y;
        while j>=1 do begin
          ans:=ans+f1[i,j]*(x+1)*(y+1);
          ans:=ans-f2[i,j]*(x+1);
          ans:=ans-f3[i,j]*(y+1);
          ans:=ans+f4[i,j];
          dec(j,lowbit(j));
        end;
        dec(i,lowbit(i));
      end;
      //writeln(x,' ',y,' ',ans);
      exit(ans);
    end;
     
    begin
      readln(ch,n,m);
      fillchar(f1,sizeof(f1),0);
      fillchar(f2,sizeof(f2),0);
      fillchar(f3,sizeof(f3),0);
      fillchar(f4,sizeof(f4),0);
      while not eof do begin
        read(ch);
        if ch='L' then begin
          readln(x1,y1,x2,y2,j);
          add(x1,y1,j);
          add(x1,y2+1,-j);
          add(x2+1,y1,-j);
          add(x2+1,y2+1,j);
        end
        else
        if ch='k' then begin
          readln(x1,y1,x2,y2);
          writeln(askans(x2,y2)+askans(x1-1,y1-1)-askans(x1-1,y2)-askans(x2,y1-1));
        end;
      end;
    end.
    View Code
  • 相关阅读:
    AC日记——与7无关的数 openjudge 1.5 39
    AC日记——计算多项式的导函数 openjudge 1.5 38
    AC日记——矩阵交换行 openjudge 1.8 01
    AC日记——阶乘和 openjudge 1.6 15
    AC日记——求10000以内n的阶乘 openjudge 1.6 14
    逻辑运算
    PLC控制设计的基本步骤
    Micropython通用控制
    class Pin --控制I/O引脚
    Micropython入门实操心得
  • 原文地址:https://www.cnblogs.com/Macaulish/p/4358180.html
Copyright © 2020-2023  润新知