Pishty and Triangles

segment-tree

#1

Can anyone tell me why this solution of mine gives tle and other is ac although they have same complexity.
The only difference between then is one of them is implements seg tree in recursive fashion and other in iterative fashion?
Question link Pishty and Triangles


#2

As you know recursive calls are more costly than iterative methods, thats the reason why you get a TLE. Your iterative method takes 5.58secs in the last test and so its fair that the recursive method easily takes more than 6secs which causes the TLE.