Need help on 903D

Revision en1, by Siriuslight, 2017-12-13 01:01:22

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. :)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Siriuslight 2017-12-13 01:01:22 604 Initial revision (published)