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代码一组..In Reply To:线段树组至少5倍...RE一次 Posted by:The_Dawn at 2011-07-12 17:25:21 type node=record l,r,c,cover:longint; end; var i,j,k,n,m,o,st,ed,color,num,ans:longint; tree:array[0..500005]of node; ch:char; procedure swap(var a,b:longint); var t:longint; begin t:=a;a:=b;b:=t; end; procedure build(w,l,r:longint); var mid:longint; begin tree[w].l:=l;tree[w].r:=r;tree[w].c:=1;tree[w].cover:=1; if l>=r then exit; mid:=(l+r)shr 1; build(2*w,l,mid); build(2*w+1,mid+1,r); end; procedure spread(w:longint); begin tree[w].cover:=0; tree[2*w].c:=tree[w].c; tree[2*w+1].c:=tree[w].c; tree[2*w].cover:=1; tree[2*w+1].cover:=1; end; function ask(w:longint):longint; var mid,tmp:longint; begin if (st<=tree[w].l)and(tree[w].r<=ed) then exit(tree[w].c); if tree[w].cover=1 then spread(w); mid:=(tree[w].l+tree[w].r)shr 1; tmp:=0; if mid>=st then tmp:=tmp or ask(2*w); if mid<ed then tmp:=tmp or ask(2*w+1); exit(tmp); end; procedure insert(w:longint); var mid:longint; begin if (st<=tree[w].l)and(tree[w].r<=ed) then begin tree[w].cover:=1; tree[w].c:=1 shl (color-1); exit; end; if tree[w].cover=1 then spread(w); mid:=(tree[w].l+tree[w].r)shr 1; if mid>=st then insert(2*w); if mid<ed then insert(2*w+1); tree[w].c:=tree[2*w].c or tree[2*w+1].c; end; begin readln(n,m,o); build(1,1,n); for i:=1 to o do begin read(ch); case ch of 'C':begin readln(st,ed,color); if st>ed then swap(st,ed); insert(1); end; 'P':begin readln(st,ed); if st>ed then swap(st,ed); num:=ask(1); ans:=0; while num<>0 do begin if num and 1=1 then inc(ans); num:=num shr 1; end; writeln(ans); end; end; end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator