记录编号 136968 评测结果 AAAAAAAWWW
题目名称 求和问题 最终得分 70
用户昵称 Gravatarsafhsdajkfhsad 是否通过 未通过
代码语言 Pascal 运行时间 0.591 s
提交时间 2014-11-03 21:15:32 内存使用 0.24 MiB
显示代码纯文本
const
  maxnum=10000;
var
  n,m,i,vx,vy:longint;
  datree,data:array[0..maxnum] of longint;

function  hslowbit(x:longint):longint;
  begin
    exit(x and (-x));
  end;

procedure gcjs(x,xx:longint);
  begin
    while (x<=n) do
      begin
        datree[x]:=datree[x]+xx;
        x:=x+hslowbit(x);
      end;
  end;

function  hsqiuhe(x:longint):longint;
  var
    pans:longint;
  begin
    pans:=0;
    while (x>0) do
      begin
        inc(pans,datree[x]);
        x:=x-hslowbit(x)
      end;
    hsqiuhe:=pans;
  end;

procedure gcshuchu(st,en:longint);
  begin
    writeln(hsqiuhe(en)-hsqiuhe(st-1));
  end;

begin
  assign(input,'sum.in');
  reset(input);
  assign(output,'sum.out');
  rewrite(output);
  readln(n);
  for i:=1 to n do
    read(data[i]);
  fillchar(datree,sizeof(datree),0);
  for i:=1 to n do
      gcjs(i,data[i]);

  readln(m);
  for i:=1 to m do
    begin
      readln(vx,vy);
      gcshuchu(vx,vy);
    end;

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