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 |
人生第一道线段树~~type node=record le,ri,lc,rc,co:longint; end; var tree:array[0..200000] of node; h:array[1..30] of boolean; l,t,o,len:longint; procedure build(ll,rr:longint); var mid,temp:longint; begin inc(len); temp:=len; tree[len].le:=ll; tree[len].ri:=rr; tree[len].co:=1; if ll+1<rr then begin mid:=(ll+rr) shr 1; tree[len].lc:=len+1; build(ll,mid); tree[temp].rc:=len+1; build(mid,rr); end; end; procedure insert(x,ll,rr,cc:longint); begin if (ll<=tree[x].le) and (tree[x].ri<=rr) then tree[x].co:=cc else begin if tree[x].co<>-1 then begin tree[tree[x].lc].co:=tree[x].co; tree[tree[x].rc].co:=tree[x].co; tree[x].co:=-1; end; if ll<tree[tree[x].lc].ri then insert(tree[x].lc,ll,rr,cc); if tree[tree[x].rc].le<rr then insert(tree[x].rc,ll,rr,cc); end; end; procedure search(x,ll,rr:longint); begin if tree[x].co>0 then h[tree[x].co]:=true else begin if ll<tree[tree[x].lc].ri then search(tree[x].lc,ll,rr); if tree[tree[x].rc].le<rr then search(tree[x].rc,ll,rr); end; end; procedure init; begin readln(l,t,o); len:=0; build(0,l); end; procedure work; var i,j,a,b,c,ans:longint; ch:char; begin for i:=1 to o do begin read(ch); if ch='C' then begin readln(a,b,c); insert(1,a-1,b,c); end else begin readln(a,b); fillchar(h,sizeof(h),false); search(1,a-1,b); ans:=0; for j:=1 to 30 do if h[j] then inc(ans); writeln(ans); end; end; end; begin init; work; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator