Implement inversion counting with BIT. core idea: an inversion with and means is "out of order" relative to .
Processing right to left: when you see , all elements you've added to the BIT are to the right of position .
Querying for elements smaller than counts exactly those forming inversions with . Alternative: use merge sort to count inversions. Both approaches are .
BIT is often simpler for competitive programming. Time: . Space: .