#P5313. Maximum Arithmetic Progression Length in Subarray

    ID: 18546 Type: Default 1000ms 256MiB

Maximum Arithmetic Progression Length in Subarray

Maximum Arithmetic Progression Length in Subarray

You are given a sequence of length nn and mm queries. For each query with parameters ll, rr, and bb, you need to determine the maximum integer xx such that there exists an integer aa with 0a<b0 \le a < b 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 ll to rr (inclusive). If none of the numbers in the range [0,b1][0, b-1] appear in the subarray, output 00.

Note: All indices are 1-indexed.

inputFormat

The first line contains two integers nn and mm (1n,m1051 \le n, m \le 10^5).

The second line contains nn integers representing the sequence.

Each of the next mm lines contains three integers ll, rr, and bb, representing a query. It is guaranteed that 1lrn1 \le l \le r \le n.

outputFormat

For each query, output a single integer: the maximum value of xx 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>