Recently,i was solving the following problem: http://codeforces.net/problemset/problem/540/E
the following is the solution i am trying to understand: http://ideone.com/cKjRNr
In the last loop of solution there are two terms,1 is to find difference of initial and final position of that element.
what about second term.according to editorial ,second term is to delete the inversions that were already counted.
so,could any one help how did we get "num[i]-i" as our second term,,whats the proof behind it..
pls help,thanks in advance.