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 |
为什么我用线段树超时了呢? 哪位大牛帮忙看看?Const Maxn=100001; var sum:qword; n,m,left,right,number:longint; Tree:array[1..Maxn*4+1] of longint; procedure Build(x,y,len:longint); var m:longint; begin if x=y then begin read(m); tree[len]:=m; exit; end; m:=(x+y) div 2; build(x,m,len*2); build(m+1,y,len*2+1); tree[len]:=tree[len*2]+tree[len*2+1]; end; procedure init; var i:longint; begin readln(n,m); Build(1,n,1); readln; end; procedure Change(x,y,len:longint); var m:longint; begin if (x>right) or (left>y) then exit; if x=y then begin inc(tree[len],number); exit; end; m:=(x+y) div 2; Change(x,m,len*2); Change(m+1,y,len*2+1); tree[len]:=tree[len*2]+tree[len*2+1]; end; procedure Count(l,r,len:longint); var m:longint; begin if (l>right) or (left>r) then exit; if (l>=left) and (right>=r) then begin sum:=sum+tree[len]; exit; end else begin m:=(l+r) div 2; count(l,m,len*2); count(m+1,r,len*2+1); end; end; procedure Main; var ch:char; i:longint; begin for i:=1 to m do begin read(ch); if ch='C' then begin readln(left,right,number); Change(1,n,1); end else begin readln(left,right); sum:=0; Count(1,n,1); writeln(sum); end; end; end; begin init; Main; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator