Hints — p92 Count Smaller After Self

  1. Reframe: for each i, count of nums[j] < nums[i] with j > i = inversion contribution.

  2. BIT approach: walk i from right to left. BIT holds the multiset of values seen so far (i.e., to the right of i). ans[i] = BIT.prefix(rank(nums[i]) - 1). Then BIT.update(rank(nums[i]), +1).

  3. Coordinate compression is necessary for arbitrary-range values: map each distinct value to its rank in sorted order.

  4. Merge sort alternative: during merge, track original indices. Each time you pop from left, add right_popped_so_far to ans[original_idx].

  5. Off-by-one: query prefix(rank - 1) to count strictly smaller; using prefix(rank) would include equal values.

If stuck: see solution.py.