FRMQ TLE - Sparse Table

For the question : FRMQ Problem - CodeChef , I used the sparse table agorithm given here :Range minimum query - PEGWiki to create a chache and then process the queries. Im getting only 70 points and subtask 3 shows TLE. My code : CodeChef: Practical coding for everyone. Can anyone give me any suggestions?

Loose the % operation.

i tried that but still getting TLE on last dataset. my code CodeChef: Practical coding for everyone

You can precalc the

next_x[i] = (i + 7) % n  
next_y[i] = (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 : CodeChef: Practical coding for everyone .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 CodeChef: Practical coding for everyone.