Team Selection2.pas 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const
  2. maxn=524688;
  3. var
  4. er:array[0..20]of longint;
  5. z,n:longint;
  6. p1:array[1..maxn]of longint;
  7. q2,q3:array[1..maxn]of longint;
  8. t:array[1..maxn*2]of longint;
  9. procedure init;
  10. var
  11. j,a:longint;
  12. begin
  13. er[0]:=1;
  14. for j:=1 to 20 do
  15. er[j]:=er[j-1]*2;
  16. readln(n);
  17. for j:=1 to 20 do
  18. if n<=er[j] then
  19. begin
  20. z:=j;
  21. break;
  22. end;
  23. for j:=1 to n do
  24. read(p1[j]);
  25. for j:=1 to n do
  26. begin
  27. read(a);
  28. q2[a]:=j;
  29. end;
  30. for j:=1 to n do
  31. begin
  32. read(a);
  33. q3[a]:=j;
  34. end;
  35. end;
  36. procedure main;
  37. var
  38. s,i,x,j,k,l,p:longint;
  39. begin
  40. fillchar(t,sizeof(t),0);
  41. s:=n;
  42. for i:=1 to n do
  43. begin
  44. k:=q3[p1[i]];
  45. l:=q2[p1[i]];
  46. for j:=z downto 0 do
  47. begin
  48. p:=er[j]-1+k;
  49. if (t[p]=0)or(t[p]>l)
  50. then t[p]:=l;
  51. if not odd(k)
  52. then if (t[p-1]<>0)and(t[p-1]<l)
  53. then begin
  54. dec(s);
  55. break;
  56. end;
  57. k:=(k+1) div 2;
  58. end;
  59. end;
  60. writeln(s);
  61. end;
  62. begin
  63. // assign(input,'team.in');
  64. // reset(input);
  65. init;
  66. main;
  67. // close(input);
  68. end.