比赛 |
防止颓废的小练习v0.15 |
评测结果 |
AAAAAAAAAA |
题目名称 |
瑞士轮 |
最终得分 |
100 |
用户昵称 |
ConanQZ |
运行时间 |
2.331 s |
代码语言 |
Pascal |
内存使用 |
7.79 MiB |
提交时间 |
2016-10-17 21:12:09 |
显示代码纯文本
program P1930;
type
node=record
num,s:int64;
end;
var
n,r,q,i:longint;
w:array[1..200010]of int64;
l1,l2:array[1..100010]of node;
a:array[1..200010]of node;
procedure sort(l,r:longint);
var
i,j,mid1,mid2:longint;
tmp:node;
begin
i:=l; j:=r;
mid1:=a[(l+r)>>1].s;
mid2:=a[(l+r)>>1].num;
repeat
while (a[i].s>mid1)or((a[i].s=mid1)and(a[i].num<mid2)) do inc(i);
while (a[j].s<mid1)or((a[j].s=mid1)and(a[j].num>mid2)) do dec(j);
if i<=j then
begin
tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp;
inc(i); dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
procedure compete;
var
k,i:longint;
begin
k:=0;
for i:=1 to n do
begin
inc(k);
if w[a[i*2-1].num]<w[a[i*2].num] then
begin
inc(a[i*2].s);
l1[k]:=a[i*2];
l2[k]:=a[i*2-1];
end
else
begin
inc(a[i*2-1].s);
l1[k]:=a[i*2-1];
l2[k]:=a[i*2];
end;
end;
end;
procedure combine;
var
k,i,j:longint;
begin
i:=1; j:=1; k:=0;
while (i<=n)and(j<=n) do
begin
inc(k);
if (l1[i].s=l2[j].s) then
begin
if l1[i].num<l2[j].num then
begin
a[k]:=l1[i];
inc(i);
end
else
begin
a[k]:=l2[j];
inc(j);
end;
end
else
begin
if (l1[i].s>l2[j].s) then
begin
a[k]:=l1[i];
inc(i);
end
else
begin
a[k]:=l2[j];
inc(j);
end;
end;
end;
if i<n then
begin
while i<=n do
begin
inc(k);
a[k]:=l1[i];
inc(i);
end;
end
else if j<n then
begin
while j<=n do
begin
inc(k);
a[k]:=l2[j];
inc(j);
end;
end;
end;
begin
//assign(input,'11.in'); reset(input);
assign(input,'swiss.in'); reset(input);
assign(output,'swiss.out'); rewrite(output);
readln(n,r,q);
for i:=1 to 2*n do
begin
read(a[i].s);
a[i].num:=i;
end;
for i:=1 to 2*n do read(w[i]);
sort(1,2*n);
for i:=1 to r do
begin
compete;
combine;
end;
writeln(a[q].num);
end.