FRMQ TLE - Sparse Table

For the question : http://www.codechef.com/problems/FRMQ , I used the sparse table agorithm given here :http://wcipeg.com/wiki/Range_minimum_query to create a chache and then process the queries. Im getting only 70 points and subtask 3 shows TLE. My code : http://www.codechef.com/viewsolution/6793372. Can anyone give me any suggestions?

Loose the % operation.

i tried that but still getting TLE on last dataset. my code http://www.codechef.com/viewsolution/6778959

You can precalc the

next_x* = (i + 7) % n  
next_y* = (i + 11) % (n - 1)

for each i in 0…n-1
then just make x = next_x[x], y = next_y[y].

I optimised the solution and was able to make it till here : http://www.codechef.com/viewsolution/6802172 .I am not able to go more further than this. Can somebody help?

Change all long long variables to long (or int) except ‘ans’

Thank you evrybody, I finally got it and its working!

I didn’t get you. Can you please elaborate?

It ran slower http://www.codechef.com/viewsolution/6800086.