count inversions of an array

in a way of merge sort, time complexity is O(nlgn)