BRCKTS spoj(segment tree)

Can someone please help me, why is my code getting TLE? What optimization could be made?

question : SPOJ.com - Problem BRCKTS
solution : J0o9Ja - Online C++0x Compiler & Debugging Tool - Ideone.com

If you find difficult to understand some part of code, let me know,

Try having update take str by reference instead of by value.

Edit:

And the same for buildTree.

2 Likes

thanks, tle problem is solved. Getting WA now :frowning:

1 Like

will these
())(()
()(())
)))(((
be considered correct bracket expression??

You tell us :slight_smile: For each expression, how would you pair the brackets using the criteria described in the question?

a.
())(()
012345

b.
()(())
012345

c.
)))(((
012345

b. is easy: \{(0,1),(2,5),(3,4)\} seems to fulfill all the criteria, to me ("(a,b)" means "pair the open bracket at index a with the closing bracket at index b").

1 Like

I misunderstood the question. Thanks @ssjgz :slight_smile:

1 Like