Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么错?。。。望前辈来指导指导//哈哈 ~pascal的~老不对。。样例都过不了。。。。。。。 var sum:array[0..200000] of longint; mark:array[0..200000] of longint; e:array[0..100001] of longint; n,q,a,b,c,l:longint; procedure init; //读入 var i:integer; c:char; begin readln(n,q); fillchar(e,sizeof(e),0); fillchar(mark,sizeof(mark),0); for i:=0 to n-1 do read(e[i]); readln; l:=1; while l<n do l:=l*2; //构造线段树,数组存的 for i:=0 to n-1 do sum[l+i]:=e[i]; for i:=l-1 downto 1 do sum[i]:=sum[i*2]+sum[i*2+1]; end; function query(id,left,right:longint):longint; //求解 var p,z1,z2:longint; begin if (left>b)or(right<a) then begin query:=0;exit;end; if (a<=left)and(b>=right) then begin inc(sum[id],mark[id]); mark[id]:=0; query:=sum[id]; if e[id]=0 then sum[id]:=0; exit; end; p:=(left+right)div 2; if mark[id]<>0 then begin inc(mark[id div 2],mark[id]); inc(mark[(id div 2)+1],mark[id]); mark[id]:=0; end; z1:=query(id*2,left,p); z2:=query((id*2)+1,p+1,right); query:=z1+z2; sum[id]:=sum[id*2]+sum[(id*2)+1]; end; procedure add(id,left,right:longint); //加标记 var p,k:longint; begin if (a>right)or(b<left) then exit; if (a<=left)and(b>=right) then begin k:=id; while k<l+n-1 do begin inc(mark[id],2*c); k:=k*2; end; end; p:=(left+right)div 2; add(id div 2,left,p); add((id div 2)+1,p,left); end; procedure solve; var ask:char; i:integer; begin for i:=1 to q do begin read(ask); if ask='C' then begin readln(a,b,c); add(1,1,l); end else if ask='Q' then begin readln(a,b); writeln(query(1,1,l)); end; end; end; begin // assign(input,'3468.in');reset(input); // assign(output,'3468.out');rewrite(output); init; solve; // close(output); // close(input); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator