SPOJ BRCKTS HELP (This Sucks)

At each node of segment tree I am storing the number of ‘(’ required to the left and number of ‘)’ required to the right to make the sequence valid. For leaf nodes this would be (1,0) for a closing bracket & (0,1) for an opening bracket.
Why I a getting wrong answer in my


[1]??
Any help is appreciated.

Anyone in the commnity please help :(

  [1]: https://ideone.com/XYLZUv

Anyone out there help me. Codechef is sick community no editorials, and people discuss shit like taran turned into a 6 star coder from accounting student or terrible icpc facilities in regionals . People take sheer interest in upvoting and commenting on such topics rather than discussing problems and helping someone . Fuck this.

Believe it or not, it’s a lot more difficult for others to debug your code if they haven’t tried the problem themselves (unless the bug is an easy one to spot.) On the contrary, if you would’ve asked some question related to some recent contests on codechef, I’m sure a lot of people would’ve volunteered to help.

I will try for sure… tomorrow…

okey dokey

I tried to debug your code but sadly I was unable to figure out the exact bug :frowning: . I recently solved this question so I can share my approach with you.

Let us store 2 values at every node of the segment tree, (i) no. of unpaired opening brackets (ii) no. of unpaired closing brackets in that particular interval. For Merging nodes, the first value will be the unpaired opening brackets from the right node(as they will not be paired with left node) plus the remaining brackets which are not paired with the unpaired closing brackets from the right node while merging. The second value can also be calculated similarly. For checking whether an expression is correct or not just check whether the two values are zero for the root node. Have a look at my code for better understanding, it is very similar to your code the only difference is I am storing 2 values instead of 4. AC Code