getting tle in GSS1 of spoj

can anyone help me by telling why my code https://ideone.com/4Y97gD for gss1 is giving tle.

just made a few optimistations,using shift operators for multiplication,division and fast io.
Your solution: https://ide.geeksforgeeks.org/p33MepdgpI

thanks @vivek_1998299 but is there any other way to get ac without using these optimizations.

I dont think so,as ur logic is absolutely right.Even if u remove shift operators it’ll still get accepted.Majority of time is consumed due to I/O.U could try coding the iterative version.

when i removed shift operators i got tle.

Your solution without shift operator: https://ide.geeksforgeeks.org/5aR7gcsaVU

Ac in 0.15

U could remove the fast io,it’ll still get accepted (just use ‘\n’ instead of endl)

thanks didn’t knew that endl could make program that slow.


Plz help @vivek_1998299. I am getting TLE even after using fast IO.

Sir Can we solve the same spoj GSS series problems using fenwick trees