getting TLE in GSS1

Why am I getting TLE in this code?

my code : C4jZxo - Online C++ Compiler & Debugging Tool - Ideone.com

problem : SPOJ.com - Problem 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 : MkHBSB - Online C++ Compiler & Debugging Tool - Ideone.com