记录编号 80912 评测结果 AAAAAAAAAA
题目名称 [NOIP 2011]瑞士轮 最终得分 100
用户昵称 Gravatar赵寒烨 是否通过 通过
代码语言 Pascal 运行时间 0.956 s
提交时间 2013-11-07 22:02:26 内存使用 4.74 MiB
显示代码纯文本
var
  n,r,q,loop,i:longint;
  num,a,w:array [1..200000] of longint;
  win,lose,winnum,losenum,winw,losew:array [1..100000] of longint;
procedure swap(var a,b:longint);
  var
    t:longint;
  begin
    t:=a;
    a:=b;
    b:=t;
  end;
procedure qsort(l,h:longint);
  var
    i,j,m,n:longint;
  begin
    i:=l;
    j:=h;
    m:=a[(i+j) div 2];
    n:=num[(i+j) div 2];
    repeat
      while (a[i]>m)or(a[i]=m)and(num[i]<n) do inc(i);
      while (a[j]<m)or(a[j]=m)and(num[j]>n) do dec(j);
      if i<=j then begin
        swap(a[i],a[j]);
        swap(num[i],num[j]);
        swap(w[i],w[j]);
        inc(i);
        dec(j);
      end;
    until i>j;
    if i<h then qsort(i,h);
    if j>l then qsort(l,j);
  end;
procedure merge;
  var
    i,j,k:longint;
  begin
    i:=1;
    j:=1;
    k:=1;
    while (i<=n)and(j<=n) do
      if (win[i]>lose[j])or(win[i]=lose[j])and(winnum[i]<losenum[j]) then begin
        a[k]:=win[i];
        num[k]:=winnum[i];
        w[k]:=winw[i];
        inc(i);
        inc(k);
      end
      else begin
        a[k]:=lose[j];
        num[k]:=losenum[j];
        w[k]:=losew[j];
        inc(j);
        inc(k);
      end;
    if i>n then
      while j<=n do begin
        a[k]:=lose[j];
        num[k]:=losenum[j];
        w[k]:=losew[j];
        inc(k);
        inc(j);
      end
    else
      while i<=n do begin
        a[k]:=win[i];
        num[k]:=winnum[i];
        w[k]:=winw[i];
        inc(k);
        inc(i);
      end;
  end;
begin
  assign(input,'swiss.in');reset(input);
  assign(output,'swiss.out');rewrite(output);
  readln(n,r,q);
  for i:=1 to 2*n do read(a[i]);
  readln;
  for i:=1 to 2*n do num[i]:=i;
  for i:=1 to 2*n do read(w[i]);
  qsort(1,2*n);
  for loop:=1 to r do begin
    for i:=1 to n do
      if w[2*i-1]>w[2*i] then begin
        win[i]:=a[2*i-1]+1;
        winnum[i]:=num[2*i-1];
        winw[i]:=w[2*i-1];
        lose[i]:=a[2*i];
        losenum[i]:=num[2*i];
        losew[i]:=w[2*i];
      end
      else begin
        win[i]:=a[2*i]+1;
        winnum[i]:=num[2*i];
        winw[i]:=w[2*i];
        lose[i]:=a[2*i-1];
        losenum[i]:=num[2*i-1];
        losew[i]:=w[2*i-1];
      end;
    merge;
  end;
  writeln(num[q]);
  close(input);
  close(output);
end.