0

I have a problem which is shown here. Can someone please suggest an approach for this problem? I looked up the editorial and it said we were supposed to create a tree for each range and treat it as a node.I am not able to understand this concept and the process of tree conversion.Thanking in advance for the help! The details of the question:

A sequence is called a correct parenthesis sequence if it's the following form:

  • Empty sequence is considered a correct parenthesis sequence.

  • (A) is considered a correct parenthesis sequence.

  • XY is considered a correct parenthesis sequence, if both X and Y are correct parenthesis sequences.

A sequence is called a strong parenthesis sequence only if it on form (A), where A is a correct parenthesis sequence.

You have to calculate a weird sum: take [i1, j1] and [i2, j2] every two subarrays of A. The subarrays must not intersect (i.e. i1 ≤ i2 and j1 ≤ i2) and must be strong parenthesis sequences. Then, we add to the sum the minimum length of a subarray, such as it is also a strong parenthesis sequence and it contains both [i1, j1] and [i2, j2] (i.e. if a subsequence of minimum length is [i3, j3], then [i3, j3] is a strong parenthesis sequence and also i3 ≤ i1 ≤ j1 ≤ j3 and i3 ≤ i2 ≤ j2 ≤ j3).

P.S. i am not able to understand the concept of tree converion for ranges and how would LCA help in this context.Thank you.

  • Rather than posting a link to the problem, can you include the relevant details inside this question itself? Also, please elaborate a bit more about what you understand and what you don't understand, since as written it's unclear what exactly you're asking for. – templatetypedef Sep 23 '16 at 19:34
  • @templatetypedef updated. – Ravi Singh Sep 24 '16 at 05:20

0 Answers0