I am trying to solve the problem matchsticks http://www.codechef.com/problems/MSTICK
I used segment tree data structure still I get TLE with a complexity O(2N + Q4*log(N))
where O(2N) for building 2 segment trees and O(4Q*log(N)) for running 4 queries on the segment tree for each query Q.
Can somebody please correct me if I am wrong about the complexity of my algorithm or help me find out why do I get TLE ?
I would appreciate it, thanks
Here is my solution http://www.codechef.com/viewsolution/4170573