How to solve this contest question ?
Given an array find sum of scores of all possible subarrays of the array.
Score of a subarray = product of min element and sum of elements in the subarray 
Max Size of array  = 8*10^5
What I did in actual test was 
Get all subarrays by varying Li, Ri (2 loops)
Get sum b/w Li , Ri using prefix sum
And then get min b/w Li, Ri using segment tree min queries

1. Prefix sum pre calculation was O(n)
2. Creating segment tree O(nlogn)
3. Looping was n square
4. Inside loop for each subarray getting sum in O(1), getting min in O(logn) using segment tree querying.

Overall O(n square log n)

We need a solution with complexity less than O(n^2)

Comments (1)