记录编号 113746 评测结果 AAAAAAAAAA
题目名称 [NOIP 2011]瑞士轮 最终得分 100
用户昵称 Gravatar传奇 是否通过 通过
代码语言 Pascal 运行时间 1.172 s
提交时间 2014-07-25 22:15:38 内存使用 34.50 MiB
显示代码纯文本
  1. program cojs625;
  2. type
  3. node=record
  4. s,w:longint;
  5. bh:longint;
  6. end;
  7. var
  8. n,r,q,i,j,l:longint;
  9. a,c,b:array[1..1000000] of node;
  10. procedure qp(l,r:longint);
  11. var
  12. i,j:longint;
  13. y,x:node;
  14. begin
  15. i:=l; j:=r;
  16. x:=a[(l+r)div 2];
  17. repeat
  18. while (a[i].s>x.s)or((a[i].s=x.s)and(a[i].bh<x.bh)) do inc(i);
  19. while (a[j].s<x.s)or((a[j].s=x.s)and(a[j].bh>x.bh)) do dec(j);
  20. if i<=j then
  21. begin
  22. y:=a[i]; a[i]:=a[j]; a[j]:=y;
  23. inc(i); dec(j);
  24. end;
  25. until i>j;
  26. if j>l then qp(l,j);
  27. if i<r then qp(i,r);
  28. end;
  29. procedure guibing(l,r:longint);
  30. var
  31. i,j,mid,p:longint;
  32. begin
  33. mid:=(l+r)div 2;
  34. i:=l; j:=mid+1; p:=l;
  35. while (i<=mid)and(j<=r) do
  36. begin
  37. if (b[i].s>b[j].s)or((b[i].s=b[j].s)and(b[i].bh<b[j].bh)) then
  38. begin
  39. c[p]:=b[i];
  40. inc(p);
  41. inc(i);
  42. end
  43. else
  44. begin
  45. c[p]:=b[j];
  46. inc(p);
  47. inc(j);
  48. end;
  49. end;
  50. while i<=mid do
  51. begin
  52. c[p]:=b[i];
  53. inc(p);
  54. inc(i);
  55. end;
  56. while j<=r do
  57. begin
  58. c[p]:=b[j];
  59. inc(j);
  60. inc(p);
  61. end;
  62. for i:=l to r do
  63. a[i]:=c[i];
  64. end;
  65. begin
  66. assign(input,'swiss.in');
  67. assign(output,'swiss.out');
  68. reset(input);
  69. rewrite(output);
  70.  
  71. readln(n,r,q);
  72. for i:=1 to n*2 do
  73. read(a[i].s);
  74. for i:=1 to 2*n do
  75. begin
  76. read(a[i].w);
  77. a[i].bh:=i;
  78. end;
  79. qp(1,2*n);
  80. for i:=1 to r do
  81. begin
  82. j:=1;l:=0;
  83. while j<2*n do
  84. begin
  85. if a[j].w>a[j+1].w then
  86. begin
  87. inc(a[j].s);
  88. inc(l);
  89. b[l]:=a[j];
  90. b[n+l]:=a[j+1];
  91. end
  92. else
  93. begin
  94. inc(a[j+1].s);
  95. inc(l);
  96. b[l]:=a[j+1];
  97. b[l+n]:=a[j];
  98. end;
  99. j:=j+2;
  100. end;
  101. guibing(1,2*n);
  102. end;
  103. writeln(a[q].bh);
  104.  
  105.  
  106. close(input);
  107. close(output);
  108. end.