you are given a sequence A[1], A[2], …, A[N] . Find the max-sum subarray in the range [L,R].
We need to answer Q queries each with two inputs L and R. (SPOJ GSS1)
We wish to solve this problem using a segment tree.
At each node of the tree that represents the segment [x…y] of the array we keep :
- SUM — sum of all numbers in this segment
- BEST — maximal sum of any subsegment of this segment
- BestLeft - maximal sum of any subsegment [i…j] of this segment, and i == x
- BestRight - maximal sum of any subsegment [i…j] of this segment, and j == y
Say node p is the parent of node c1(left child) and c2(right child) in the segment tree.
choose the correct option :
All of these are correct…
p.SUM = c1.SUM + c2.SUM
p.BEST = max(max(c1.BEST, c2.BEST) , c1.BestRight + c2.BestLeft)
p.BestLeft = max(c1.BestLeft, c1.SUM + c2.BestLeft)
Please expalin me the output of thequestion