Inversion Count (APCS 2018-06 Expert)
2.0s 256MCount index pairs \((i,j)\) with \(i<j\) and \(a_i>a_j\). Different index pairs count separately, even if their values coincide.
Input Format
Read \(n\), then the \(n\) values.
Output Format
Print the inversion count.
Constraints
\(1\le n\le100000\), \(0\le a_i\le1000000\).
Sample Input
6
3 1 9 8 9 2
Sample Output
6
Source
APCS 2018-06 public archive version: tcirc:d064。
Log in to write and submit code.
Log in