Given an array A of n integers. M queries are given in the form of l, r. For each query, I need to count the number of inversions in subarray A from l to r. I know the offline approach to solve this using BIT and sqrt decomposition.
Is it possible to solve this problem online using segment tree or any other data structure?