I was solving the problem C. Sereja and Brackets from codeforces, but editorial provided by them is very fast paced, can anyone please explain in detail how this problem will be solved.

We will support the segments tree. At each vertex will be stored:

av β the maximum length of the bracket subsequence

bv β how many there it open brackets that sequence doesnβt contain

cv β how many there it closed brackets that sequence doesnβt contain

For eg:- First range[L1 to R1] in which a1,b2,c2 are the values and second range[L2 to R2] in which a2,b2,c2.

Now we have to find for range[L1 to R2] or means combining the first and second range. Then a3,b3,c3 are to be set.First we try to find if any new bracket if formed or not.We can find it by min(b1,c2).It is becuase to the a new brackets can only formed when there are some open brackets in left range and some close brackets in right range.

t=min(b1,c2) // no of minimum new brackets formed

aβ=βa1β+βa2β+βt // total no of brackets = (total brackets in left range) + (total brackets in right range) + (new brackets formed)

bβ=βb1β+βb2β-βt // total no of open brackets which are not paired=(totals open brackets which are not paired in left range) + (total open brackets which are not paired in right range) - (total no of open brackets that are used to make new brackets )

cβ=βc1β+βc2β-βt // total no of closed brackets which are not paired=(totals closed brackets which are not paired in left range) + (total closed brackets which are not paired in right range) - (total no of closed brackets that are used to make new brackets )

Thanks, very nice explanation.

Can you please explain how should I could it, looks slightly different from traditional segment tree problems.