Count inversion pairs of an array containing 1 to n in O(nlogn) time