fork download
  1. const maxn=70000;
  2. type mang=array[0..maxn+2] of longint;
  3. var a:mang; n,i:longint; res:int64;
  4. function cinv(len:longint;var a:mang):int64;
  5. var i,j,k,nl,nr:longint;
  6. x,y,z:int64;
  7. l,r:mang;
  8. begin
  9. if (len<=1) then begin cinv:=0; exit; end;
  10. nl:=len div 2; nr:=len-nl;
  11. for i:=0 to nl-1 do l[i]:=a[i];
  12. for i:=nl to len-1 do r[i-nl]:=a[i];
  13. x:=cinv(nl,l); y:=cinv(nr,r);
  14. j:=0; r[nr]:=maxlongint; l[nl]:=maxlongint;
  15. z:=0;
  16. for i:=0 to nl-1 do begin
  17. while l[i]>r[j] do inc(j);
  18. z:=z+j;
  19. end;
  20. i:=0;j:=0;
  21. for k:=0 to len-1 do begin
  22. if (l[i]<=r[j]) then begin
  23. a[k]:=l[i]; inc(i);
  24. end else begin
  25. a[k]:=r[j]; inc(j);
  26. end;
  27. end;
  28. cinv:=x+y+z;
  29. end;
  30. begin
  31. assign(input,''); reset(input);
  32. assign(output,''); rewrite(output);
  33. //readln(n); for i:=0 to n-1 do read(a[i]);
  34. n:=maxn; for i:=0 to n-1 do a[i]:=n-i;
  35. res:=cinv(n,a);
  36. write(res);
  37. close(input); close(output);
  38. end.
Runtime error #stdin #stdout 0.01s 8064KB
stdin
Standard input is empty
stdout
Standard output is empty