You are given an array A of positive integers and some queries.
In each query, you are given positive integers X, Y, l and r.
For each query, you are to find the maximum element in range [l : r] of array A, which is more than X and less than Y. If no such element present, output -1.
I had an explanation of similar question where you are to find the maximum element less than K in a range of array. But here I am not able to apply that logic.
Expected time is O(log n) or polylogarithmic time.