zoukankan      html  css  js  c++  java
  • [vijos P1512] SuperBrother打鼹鼠

    这周好好码树状数组和线段树!!之前没写过二维树状数组,凭借一维的思路居然写了个比较像模像样的东西出来,原来我没那么脑残。唯一要注意的就是getsum四个矩形加减的边界条件,这里看了别人标程才意识到错误QAQ!

    program vijos_p1512;
    var f,t:array[0..1030,0..1030] of longint;
        n,m,i,j,x,y,k,x1,x2,y1,y2:integer;
        ans:longint;
    function lowbit(x:longint):longint;
    begin
      lowbit:=x and (-x);
    end;
    
    procedure add(x,y,delta:longint);
    var ty:longint;
    begin
      ty:=y;
      while (x<=n) do
        begin
          while (y<=n) do
            begin
              inc(f[x,y],delta);
              y:=y+lowbit(y);
            end;
          x:=x+lowbit(x);
          y:=ty;
        end;
    end;
    
    function getsum(x,y:longint):longint;
    var ty,p:longint;
    begin
      ty:=y;p:=0;
      while (x>0) do
        begin
          while (y>0) do
            begin
              inc(p,f[x,y]);
              y:=y-lowbit(y);
            end;
          x:=x-lowbit(x);
          y:=ty;
        end;
      getsum:=p;
    end;
    
    begin
      readln(n);
      read(m);
      while m<>3 do
        begin
          if m=1 then
            begin
              readln(x,y,k);
              add(x+1,y+1,k);
            end;
          if m=2 then
            begin
              readln(x1,y1,x2,y2);
              ans:=getsum(x2+1,y2+1)-getsum(x1,y2+1)-getsum(x2+1,y1)+getsum(x1,y1);
              writeln(ans);
            end;
          read(m);
        end;
    end.
    SuperBrother打鼹鼠

    测试数据 #0: Accepted, time = 0 ms, mem = 4780 KiB, score = 10

    测试数据 #1: Accepted, time = 46 ms, mem = 4776 KiB, score = 10

    测试数据 #2: Accepted, time = 7 ms, mem = 4776 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 4780 KiB, score = 10

    测试数据 #4: Accepted, time = 46 ms, mem = 4776 KiB, score = 10

    测试数据 #5: Accepted, time = 15 ms, mem = 4776 KiB, score = 10

    测试数据 #6: Accepted, time = 15 ms, mem = 4780 KiB, score = 10

    测试数据 #7: Accepted, time = 15 ms, mem = 4772 KiB, score = 10

    测试数据 #8: Accepted, time = 31 ms, mem = 4780 KiB, score = 10

    测试数据 #9: Accepted, time = 31 ms, mem = 4776 KiB, score = 10

    (神马居然没秒杀?难道还有更快做法?!)

  • 相关阅读:
    实例讲解虚拟机3种网络模式(桥接、nat、Host-only)
    期刊搜索问题——SCI、EI、IEEE和中文期刊
    面向对象分析与设计(C++)课堂笔记
    windows与VMware ubuntu虚拟机实现文件共享
    GDI+在绘制验证码中的使用
    【转】.net中快捷键的使用
    MD5加密“破解”在.NET平台实现最基本的理解
    UE4 Persona 骨架网格物体动画
    从零开始做3D地图编辑器 基于QT与OGRE
    TBB(Intel Threading Building Blocks)学习笔记
  • 原文地址:https://www.cnblogs.com/Sky-Grey/p/3579389.html
Copyright © 2011-2022 走看看