Help Required in LUNCHTIM

I built a Segment Tree for Max in a Range queries. Between two occurrences of same height entries, if the maximum in this range comes out to be this height, then they should satisfy criteria.

https://www.codechef.com/viewsolution/44249937

I tried hard to debug but in vain.
I wonder why it passes the First Subtask and fails the second lol.
Any help would be greatly appreciated.

Update : Resolved a bug and got AC. It was a silly mistake in logic.

Link : CodeChef: Practical coding for everyone