记录编号 |
58797 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列操作C |
最终得分 |
100 |
用户昵称 |
FrCsKOH |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.366 s |
提交时间 |
2013-04-26 18:49:14 |
内存使用 |
5.16 MiB |
显示代码纯文本
program P1317;
var dA,dIAp:array[0..262144] of int64;
S:array[0..131072] of int64;
Cu,n,m,i,t:longint;
A,B,D:int64;
Tk:ansistring;
function Con(s:int64):int64;
begin
Con:=0;
while 1<<Con<s+2 do inc(Con);
Con:=1<<Con;
end;
function Query(L,R:int64):int64;
var p,q:longint;
begin
p:=L;
q:=R;
inc(L,Cu-1);
inc(R,Cu+1);
Query:=0;
while L xor R<>1 do begin
if L and 1=0 then inc(Query,dA[L+1]);
if R and 1=1 then inc(Query,dA[R-1]);
L:=L>>1;
R:=R>>1;
end;
Query:=Query*(q+1);
L:=p;
R:=q;
inc(L,Cu-1);
inc(R,Cu+1);
while L xor R<>1 do begin
if L and 1=0 then dec(Query,dIAp[L+1]);
if R and 1=1 then dec(Query,dIAp[R-1]);
L:=L>>1;
R:=R>>1;
end;
end;
procedure Add(t,D,Dk:int64);
begin
inc(t,Cu);
while t<>0 do begin
inc(dA[t],D);
inc(dIAp[t],Dk);
t:=t>>1;
end;
end;
begin
assign(input,'shuliec.in');
reset(input);
assign(output,'shuliec.out');
rewrite(output);
readln(n);
Cu:=Con(n);
S[0]:=0;
for i:=1 to n do begin
read(S[i]);
dA[i+Cu]:=S[i]-S[i-1];
dIAp[i+Cu]:=dA[i+Cu]*i;
end;
readln;
for i:=Cu-1 downto 1 do begin
dA[i]:=dA[i<<1]+dA[i<<1+1];
dIAp[i]:=dIAp[i<<1]+dIAp[i<<1+1];
end;
readln(m);
for i:=1 to m do begin
readln(Tk);
case Tk[1] of
'S':begin
t:=pos(' ',Tk);
delete(Tk,1,t);
t:=pos(' ',Tk);
val(copy(Tk,1,t-1),A);
delete(Tk,1,t);
val(Tk,B);
if (B=1) and (A=1) then writeln(Query(1,1))
else
if (A=1) and (B<>1) then writeln(Query(1,B))
else writeln(Query(1,B)-Query(1,A-1));
end;
'A':begin
t:=pos(' ',Tk);
delete(Tk,1,t);
t:=pos(' ',Tk);
val(copy(Tk,1,t-1),A);
delete(Tk,1,t);
t:=pos(' ',Tk);
val(copy(Tk,1,t-1),B);
delete(Tk,1,t);
val(Tk,D);
Add(A,D,D*A);
if B<n then Add(B+1,-D,-D*(B+1));
end;
end;
end;
close(input);
close(output);
end.