For each element, scanning all elements to its right takes . Total: . For , that's operations.
Example: nums = [5, 2, 6, 1]. For : count smaller = . For : count smaller = . Scanning rightward for each element is slow.
Merge sort while counting inversions, or segment tree for range queries. Process right to left, query count of elements smaller than current, then add current to structure. .