记录编号 138801 评测结果 AAAAAAAAA
题目名称 数列操作B 最终得分 100
用户昵称 Gravatar筽邝 是否通过 通过
代码语言 Pascal 运行时间 0.139 s
提交时间 2014-11-06 15:27:47 内存使用 0.93 MiB
显示代码纯文本
program cojs1316;
var
  a:array[1..100010]of longint;
  b:array[1..100010]of longint;
  ans,n,m,i,j,l,r,x,d:longint;
  ch:char;

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

function query(x:longint):longint;
var
  t,p:longint;
begin
  p:=x; t:=0;
  while p<=n do
  begin
    inc(t,b[p]);
    inc(p,lowbit(p));
  end;
  exit(t+a[x]);
end;

procedure add(x,d:longint);
begin
  while x>0 do
  begin
    inc(b[x],d);
    dec(x,lowbit(x));
  end;
end;

begin
assign(input,'shulieb.in');reset(input);
assign(output,'shulieb.out');rewrite(output);

  readln(n);
  for i:=1 to n do
    read(a[i]);
  readln; readln(m);
  for i:=1 to m do
  begin
    read(ch);
    if ch='Q' then
    begin
      for j:=1 to 4 do
        read(ch);
      readln(x);
      ans:=query(x);
      writeln(ans);
    end else begin
      for j:=1 to 3 do
        read(ch);
      readln(l,r,d);
      add(r,d);
      add(l-1,-d);
    end;
  end;

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