#C11362. Arithmetic Subsequence Query
Arithmetic Subsequence Query
Arithmetic Subsequence Query
You are given an array of integers and several queries. In each query, you are provided with two indices l and r (1-indexed) that define a subarray, and an integer d which is the common difference. Your task is to determine whether there exists a subsequence (not necessarily contiguous, but following the original order) of at least three elements within the subarray that forms an arithmetic progression with the common difference \(d\). An arithmetic progression is a sequence where the difference between consecutive elements is constant. For instance, in a valid progression \(a, b, c\), it must be that \(b - a = d\) and \(c - b = d\).
Note that while the subsequence does not have to be contiguous, the relative order of the chosen elements must be maintained. If such a subsequence exists for a query, output "Yes"; otherwise, output "No".
inputFormat
The input is given from standard input (stdin) in the following format:
n a1 a2 ... an q l1 r1 d1 l2 r2 d2 ... lq rq dq
where:
n
is the number of elements in the array.- The second line contains
n
space-separated integers representing the array elements. q
is the number of queries.- Each of the next
q
lines contains three integersl
,r
, andd
, wherel
andr
represent the inclusive 1-indexed boundaries of the subarray, andd
is the common difference for the arithmetic progression.
It is guaranteed that the indices provided in the queries are valid.
outputFormat
For each query, print "Yes" (without quotes) on a new line if there exists a subsequence of at least three elements in the subarray [l, r] that forms an arithmetic progression with common difference d
. Otherwise, print "No".## sample
6
1 3 5 7 9 11
2
1 6 2
2 5 4
Yes
No
</p>