Comments

This blog post explains how to use a BIT for counting inversions.

Great tutorial! Thanks for your effort.

Did you submit the solution you described here for SPOJ POSTERS? I ask because I am not convinced that a solution using segment trees and co-ordinate compression is possible. The only implementations I have found that try to do this fail on the following test case:

1
3
3 7
1 3
7 10

The expected output is 3 but segment tree/coordinate compression solutions give 2.

Can you point me to an implementation using segment trees and co-ordinate compression that can deal with this case? My own attempt is here.