记录编号 |
217650 |
评测结果 |
AAAAAAAAA |
题目名称 |
数列操作B |
最终得分 |
100 |
用户昵称 |
Marvolo |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.176 s |
提交时间 |
2016-01-05 13:15:22 |
内存使用 |
6.65 MiB |
显示代码纯文本
program zht;
type zy=record
l,r,d:longint;
end;
var
x,y,d,lj,i,j,n,m:longint;
z,b:char;
a:array[0..200000] of longint;
t:array[0..500000] of zy;
procedure maketree(low,high,bh:longint);
var
mid:longint;
begin
mid:=0;
t[bh].l:=low;
t[bh].r:=high;
if low=high then
begin
t[bh].d:=a[low]; exit; end;
mid:=(low+high) div 2;
maketree(low,mid,bh*2);
maketree(mid+1,high,bh*2+1);
end; // jian shu
procedure query(bh,a:longint);
var
mid:longint;
begin
mid:=0;
if t[bh].l=t[bh].r then begin lj:=lj+t[bh].d; writeln(lj); exit; end;
lj:=lj+t[bh].d;
mid:=(t[bh].l+t[bh].r) div 2;
if a<=mid then query(bh*2,a) else query(bh*2+1,a);
end; // cha zhao
procedure add(bh,ml,mr:longint);
var
mid:longint;
begin
mid:=0;
if (ml=t[bh].l) and (mr=t[bh].r) then begin t[bh].d:=t[bh].d+d; exit; end;
mid:=(t[bh].l+t[bh].r) div 2;
if mr<=mid then begin add(bh*2,ml,mr); exit; end;
if ml>mid then begin add(bh*2+1,ml,mr); exit; end;
add(bh*2,ml,mid);
add(bh*2+1,mid+1,mr);
end; // tian jia
begin
assign(input,'shulieb.in');
assign(output,'shulieb.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
read(a[i]);
maketree(1,n,1);
readln(m);
for i:=1 to m do
begin
x:=0;
y:=0;
d:=0;
lj:=0;
read(b);
read(z);
while z<>' ' do
read(z);
if b='Q' then begin readln(x); query(1,x); end;
if b='A' then begin readln(x,y,d); add(1,x,y); end;
end;
close(input);
close(output);
end.