ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1510. Order

Could anyone tell me why it WA#2?
Posted by RTW 20 Apr 2008 19:32
Could anyone tell me why it WA#2?


program p1510_Use_QSort;

var
  d:array[1..500000]of longint;
  n,i,j,max,maxh:longint;

procedure qsort(s,t:longint);
  var
    i,j,p:longint;
  begin
  //make it randomize
    p:=random(t-s)+s+1;
    d[s]:=d[s] xor d[p];
    d[p]:=d[s] xor d[p];
    d[s]:=d[s] xor d[p];
  //start sort
    i:=s;j:=t;
    while true do begin
      while (i<j)and(d[i]<=d[j]) do dec(j);
      if i=j then break;
      d[i]:=d[i] xor d[j];d[j]:=d[i] xor d[j];d[i]:=d[i] xor d[j];
      while (i<j)and(d[i]<=d[j]) do inc(i);
      if i=j then break;
      d[i]:=d[i] xor d[j];d[j]:=d[i] xor d[j];d[i]:=d[i] xor d[j];
    end;
    dec(i);inc(j);
    if s<i then qsort(s,i);
    if j<t then qsort(j,t);
  end;

begin
  readln(n);
  for i:=1 to n do read(d[i]);
  randomize;
  qsort(1,n)
  writeln(d[n shr 1+1]);
end.