I have implemented 903D using Mergesort Tree and maintaining a prefix sum vector for every vector of merge sort tree.
For every a[i], I am calculating the sum of all a[j], where a[j] > a[i]+1 or a[j] < a[i]-1, j < i. Using this sum I am subtracting this sum from answer and adding a[i], same number of times.
My submission. This error is because of integer overflow, but when I change all integers to long long. It gives me wrong answer.
Any help would be appreciated. :)