I have given a an array A
of n integer , and Q
query in the form of X D
for each query i have to find the maximum element in sub array [Ax , A(x-D),A(x-2D)..]
For example:
A = [1,2,3,4,5,6,17,8]
we have query 7 2
Sub Array [17,5,3,1] Ans=17
How can we solve this with a time complexity better than O(Q*N)
since no index is updated , can it be solved offline with some technique
I don't think Square Decomposition
will work here.