记录编号 |
84658 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2011]瑞士轮 |
最终得分 |
100 |
用户昵称 |
明天 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.945 s |
提交时间 |
2013-12-17 22:16:22 |
内存使用 |
6.33 MiB |
显示代码纯文本
const
maxn=100000;
type
anode=record
number,s,w:longint;
end;
atype=array[1..maxn*2] of anode;
var
a,b,c:atype;
n,r,q,i,j,k:longint;
procedure qsort(l,r:longint);
var
i,j,x,y,temp:longint;
t:anode;
begin
i:=l; j:=r;
temp:=random(r-l+1)+l;
x:=a[temp].s;
y:=a[temp].number;
repeat
while (a[i].s>x)or((a[i].s=x)and(a[i].number<y)) do inc(i);
while (a[j].s<x)or((a[j].s=x)and(a[j].number>y)) do dec(j);
if i<=j then
begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
procedure merge(l,r:longint);
var
i,j,k:longint;
begin
i:=l; j:=l; k:=l-1;
while (i<=r)and(j<=r) do
begin
inc(k);
if (b[i].s>c[j].s)or((b[i].s=c[j].s)and(b[i].number<c[j].number)) then
begin
a[k]:=b[i]; inc(i);
end
else begin
a[k]:=c[j]; inc(j);
end;
end;
while i<=r do
begin inc(k); a[k]:=b[i]; inc(i); end;
while j<=r do
begin inc(k); a[k]:=c[j]; inc(j); 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 begin a[i].number:=i;read(a[i].s); end;
readln;
for i:=1 to 2*n do read(a[i].w);
qsort(1,2*n);
for j:=1 to r do
begin
i:=1; k:=0;
while i<=2*n do
begin
inc(k);
if a[i].w>a[i+1].w then
begin inc(a[i].s); b[k]:=a[i]; c[k]:=a[i+1]; end
else begin inc(a[i+1].s); b[k]:=a[i+1]; c[k]:=a[i]; end;
inc(i,2);
end;
merge(1,n);
end;
writeln(a[q].number);
close(input); close(output);
end.