|
|
back to boardwhy WA #17? why WA #17? who can help me.... type node=record dat,num:longint; end; var a:array[1..30000]of node; s:array[1..30000]of longint; m:longint; i,j,t,k:longint; procedure heap1(x,y:longint); var i,j:longint; k:node; begin i:=x;j:=i*2;k:=a[x]; while j<=y do begin if (a[j+1].dat>a[j].dat)and(j<y) then inc(j); if k.dat>=a[j].dat then j:=y+1 else begin a[i]:=a[j];s[a[j].num]:=i; i:=j;j:=i*2; end; end; a[i]:=k;s[k.num]:=i; end; procedure heap2(x,y:longint); var i,j:longint; k:node; begin i:=y;j:=y shr 1; k:=a[y]; while j>=1 do if a[j].dat>=k.dat then j:=0 else begin a[i]:=a[j];s[a[j].num]:=i; i:=j;j:=j shr 1; end; a[i]:=k;s[k.num]:=i; end; begin
readln(m); for i:=1 to m do begin readln(a[i].dat); s[i]:=i; a[i].num:=i; end; for i:=m shr 1 downto 1 do heap1(i,m); writeln(a[1].dat); t:=m+1; readln(k); while k<>-1 do begin s[a[m].num]:=s[t-m]; a[s[t-m]]:=a[m]; heap1(1,m-1); a[m].dat:=k; a[m].num:=t; s[t]:=m; heap2(1,m); writeln(a[1].dat); inc(t); readln(k); end; end. |
|
|