The solution comes down to a single observation that if [l,m1] and [m2,r] are two halves of the segment [l,r], then the values we add to the answer while processing [m2,r] are the same as the values we add while processing [l,m1] just shifted by (l+r)/2.
The solution comes down to a single observation that if
[l,m1]and[m2,r]are two halves of the segment[l,r], then the values we add to the answer while processing[m2,r]are the same as the values we add while processing[l,m1]just shifted by(l+r)/2.