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 |
WA了无数次,哪个好心人出一下数据。。。。。我的程: program pku2777; // {$I-,Q-,R-,S-} const maxn=100000; type treedata=record c,l,r,i,j:longint; f:boolean; end; var tree:array [1..maxn*2] of treedata; top:longint; procedure build(r,i,j:longint); var w:longint; begin tree[r].i:=i; tree[r].j:=j; tree[r].c:=1; tree[r].f:=true; if i=j then begin tree[r].l:=0; tree[r].r:=0; end else begin inc(top); tree[r].l:=top; inc(top); tree[r].r:=top; w:=(i+j) div 2; build(tree[r].l,i,w); build(tree[r].r,w+1,j); end; end; procedure insert(root,i,j,c:longint); var l,r:longint; begin if (tree[root].i=i) and (tree[root].j=j) then begin tree[root].f:=true; tree[root].c:=1 shl (c-1); exit; end; l:=tree[root].l; r:=tree[root].r; if tree[root].f then begin tree[l].f:=true; tree[l].c:=tree[root].c; tree[r].f:=true; tree[r].c:=tree[root].c; end; if j<=tree[l].j then insert(l,i,j,c) else if tree[r].i<=i then insert(r,i,j,c) else begin insert(l,i,tree[l].j,c); insert(r,tree[r].i,j,c); end; tree[root].f:=tree[l].f and tree[r].f and (tree[l].c=tree[r].c); tree[root].c:=tree[l].c or tree[r].c; end; function ask(root,i,j:longint):longint; var l,r:longint; begin if (tree[root].i=i) and (tree[root].j=j) then exit(tree[root].c); l:=tree[root].l; r:=tree[root].r; if j<=tree[l].j then exit(ask(l,i,j)) else if tree[r].i<=i then exit(ask(r,i,j)) else ask:=ask(l,i,tree[l].j) or ask(r,tree[r].i,j); end; procedure swap(var a,b:longint); var c:longint; begin c:=a;a:=b;b:=c; end; procedure main; var i,l0,t,o,a,b,c:longint;ch:char; begin readln(L0,T,O); top:=1; build(1,1,l0); for i:=1 to o do begin read(ch); if ch='C' then begin readln(a,b,c); if a>b then swap(a,b); insert(1,a,b,c); end else begin readln(a,b); if a>b then swap(a,b); c:=ask(1,a,b); b:=0; for a:=0 to t-1 do if (1 shl a) and c>0 then inc(b); writeln(b); end; end; end; begin main; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator