#P5313. Maximum Arithmetic Progression Length in Subarray
Maximum Arithmetic Progression Length in Subarray
Maximum Arithmetic Progression Length in Subarray
You are given a sequence of length and queries. For each query with parameters , , and , you need to determine the maximum integer such that there exists an integer with for which the arithmetic progression $$a,; a+b,; a+2b,; \ldots,; a+(x-1)b$$ appears at least once in the subarray of the given sequence from index to (inclusive). If none of the numbers in the range appear in the subarray, output .
Note: All indices are 1-indexed.
inputFormat
The first line contains two integers and ().
The second line contains integers representing the sequence.
Each of the next lines contains three integers , , and , representing a query. It is guaranteed that .
outputFormat
For each query, output a single integer: the maximum value of satisfying the condition described.
sample
6 3
1 3 2 4 3 5
1 6 2
2 5 2
2 6 3
3
0
2
</p>