Pagini recente » Cod sursa (job #1897232) | Cod sursa (job #1187502) | Cod sursa (job #151420) | Monitorul de evaluare | Cod sursa (job #743579)
Cod sursa(job #743579)
Program p1;
var bufi,bufa : array[0..1 shl 22] of char;
i,n,m,a,b,sol : longint; t1:byte;
max:array[1..90001] of longint;
Procedure creare(left,right,nod:longint);
var mijl:longint;
begin
if left=right then read(max[nod])
else begin
mijl:=(left+right) div 2;
creare(left,mijl,2*nod);
creare(mijl+1,right,2*nod+1);
max[nod]:=max[2*nod]+max[2*nod+1];
end;
end;
Procedure caut(left,right,nod:longint);
var mijl:longint;
begin
if (a<=left) and (b>=right) then begin
sol:=sol+max[nod];
end
else begin
mijl:=(left+right) div 2;
if a<=mijl then caut(left,mijl,2*nod);
if b>=mijl+1 then caut(mijl+1,right,2*nod+1);
end;
end;
Procedure update(left,right,nod:longint);
var mijl:longint;
begin
if left=right then max[nod]:=max[nod]-b
else begin
mijl:=(left+right) div 2;
if a<=mijl then update(left,mijl,2*nod)
else update(mijl+1,right,2*nod+1);
max[nod]:=max[2*nod]+max[2*nod+1];
end;
end;
begin
assign(input,'datorii.in'); reset(input);
assign(output,'datorii.out'); rewrite(output);
settextbuf(input,bufi); settextbuf(output,bufa);
readln(n,m);
creare(1,n,1);
for i:=1 to m do begin
readln(t1,a,b);
if t1=0 then update(1,n,1)
else begin
sol:=0;
caut(1,n,1);
writeln(sol);
end;
end;
close(input); close(output);
end.