getting TLE in GSS1

gss1
spoj

#1

Why am I getting TLE in this code?

my code : http://ideone.com/C4jZxo

problem : http://www.spoj.com/problems/GSS1/

I saw some solutions while googling and I don’t think they are using lazy updates. What can I do?

p.s. I modified the code which I think makes code a bit faster. But still I am getting a TLE verdict.

code : http://ideone.com/MkHBSB