Devise an O(n log n) algorithm to count all the inversions in a bitstring x of length n, for each k from 1 to n-1. Assume constant time arithmetic on real numbers. Which of the following options correctly describes the algorithm?
A. O(n^2) algorithm that counts inversions for each k from 1 to n-1.
B. O(n) algorithm that counts inversions for each k from 1 to n-1.
C. O(n log n) algorithm that counts inversions for each k from 1 to n.
D. O(n log n) algorithm that counts inversions for each k from 0 to n-1.