fork download
  1. // nongdanjohn - THPTNguyen-Quang-Dieu
  2. const maxN = 100001;
  3. var N: longint;
  4. A: array[1..maxN] of longint;
  5. Link,Head: array[1..maxN] of longint;
  6. Free: array[1..maxN] of boolean;
  7.  
  8. Procedure Enter;
  9. var i: longint;
  10. begin
  11. Readln(N);
  12. For i:=1 to N do Read(A[i]);
  13. For i:=N downto 1 do
  14. if Free[A[i]] then
  15. begin
  16. Head[A[i]]:=i;
  17. Link[i]:=i;
  18. Free[A[i]]:=False;
  19. end else
  20. begin
  21. link[i]:=head[A[i]];
  22. Head[A[i]]:=i;
  23. end;
  24. end;
  25.  
  26. Procedure Sort(L,H: longint);
  27. var i,j,k,t: longint;
  28. begin
  29. i:=l; j:=h; k:=A[(l+h) div 2];
  30. repeat
  31. while A[i]<k do inc(i);
  32. while A[j]>k do dec(j);
  33. if i<=j then
  34. begin
  35. t:=A[i]; A[i]:=A[j]; A[j]:=t;
  36. inc(i); dec(j);
  37. end;
  38. until i>j;
  39. if l<j then sort(l,j);
  40. if i<h then sort(i,h);
  41. end;
  42.  
  43. procedure solve;
  44. var i,j,res: longint;
  45. begin
  46. Fillchar(Free, sizeof(Free), true);
  47. res:=0;
  48. for i:=1 to n do
  49. begin
  50. j:=head[A[i]];
  51. if Free[j] then
  52. begin
  53. inc(res);
  54. Free[j]:=False; Free[j+1]:=False; Free[j-1]:=False;
  55. end;
  56. head[A[i]]:=Link[j];
  57. end;
  58. Writeln(Res);
  59. end;
  60.  
  61. Begin
  62. Assign(Input,''); Reset(Input);
  63. Enter;
  64. Sort(1,n);
  65. solve;
  66. End.
Success #stdin #stdout 0s 1544KB
stdin
Standard input is empty
stdout
0