FRMQ TLE - Sparse Table

For the question : , I used the sparse table agorithm given here : to create a chache and then process the queries. Im getting only 70 points and subtask 3 shows TLE. My code : Can anyone give me any suggestions?

Loose the % operation.

i tried that but still getting TLE on last dataset. my code

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

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].

It ran slower

I optimised the solution and was able to make it till here : .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!