Consider a array (0 based index) i have to find the sum of distinct element of all possible range[i,n] where 0< i < n
Example:
arr={1,2,1,3}
sum_range[0,3]={1,2,3}=6
sum_range[1,3]={1,2,3}=6
sum_range[2,3]={1,3}=4
sum_range[3,3]={3}=3
O(n^2) solution is one possible solution and i have read persistent segment tree can also do this though i can't find good tutorial.
Can it be solved in less than O(N^2) time?
If someone points persistent segment tree please explain or provide some good link?