According to the editorial,
sum of all lengths of distinct element subarrays in this subarray is ((j-i) * (j-i+1))/2 .
How? the possible lengths of subarrays are 1, 2, 3,……, j – i +1. So, the sum will be ((j – i ) * (j – i +1))/2.
But the lengths can repeat right? in the given sample input we have 3 subarrays of length 1.So how can you apply the formula of sum of n natural numbers there??