UVa 10810 - Ultra-QuickSort

10810 - Ultra-QuickSort

 * http://acm.uva.es/p/v108/10810.html

Summary
To find number of adjacent swaps necessary to sort a given sequence of integers.

Explanation
You have to find the inversion index of a sequence. In a sequence $$A$$, the elements $$i, j$$ is an inversion of $$A$$ if $$A_i > A_j$$.

Easy bubble sort algorithm will be too slow. Modify the merge sort to a little extent. During merging when an element from right set is inserted prior to some elements in the left set, it means, that element is actually adjacently swapped with them.

Note
Number of swaps will be too big to hold in a 32 bit data-type.

Input
5 9 1 0 5 4 3 1 2 3 5 5 2 3 4 1 0

Output
6 0 7