fork(1) download
  1. uses math;
  2. const fi='';
  3. fo='';
  4. maxn = 60000+3;
  5. var t :array[1..maxn*4] of longint;
  6. i,j,n :longint;
  7. a :ARRAY[1..maxn] of longint;
  8. ma :longint;
  9. res :int64;
  10. procedure enter;
  11. begin
  12. assign(input,fi);reset(input);
  13. readln(n);for i:=1 to n do read(a[i]);
  14. close(input);
  15. end;
  16. procedure update(k,l,r,i:longint);
  17. var m :longint;
  18. begin
  19. if (i<l) or (i>r) then exit;
  20. if l=r then
  21. begin
  22. inc(t[k]);
  23. exit;
  24. end;
  25. m := (l+r) div 2;
  26. update(k*2,l,m,i);
  27. update(k*2+1,m+1,r,i);
  28. t[k] := t[k*2] + t[k*2+1];
  29. end;
  30. function get(k,l,r,i,j:longint):longint;
  31. var m,tam1,tam2 :longint;
  32. begin
  33. if i>j then exit(0);
  34. if (i>r) or (j<l) then exit(0);
  35. if (i<=l) and (j>=r) then
  36. begin
  37. exit(t[k]);
  38. end;
  39. m := (l+r) div 2;
  40. tam1 := get(k*2,l,m,i,j);
  41. tam2 := get(k*2+1,m+1,r,i,j);
  42. get:= tam1+tam2;
  43. end;
  44. procedure process;
  45. var i :longint;
  46. begin
  47. for i:=1 to n do ma := max(ma,a[i]);
  48. res := 0;
  49. for i:=1 to n do
  50. begin
  51. res := res + get(1,1,ma,a[i]+1,ma);
  52. update(1,1,ma,a[i]);
  53. end;
  54. end;
  55. procedure print;
  56. begin
  57. assign(output,fo);rewrite(output);
  58. writeln(res);
  59. close(output);
  60. end;
  61. begin
  62. enter;
  63. process;
  64. print;
  65. end.
Success #stdin #stdout 0s 1768KB
stdin
Standard input is empty
stdout
0