#P5355. Cornfield Query Challenge
Cornfield Query Challenge
Cornfield Query Challenge
Yuina, while taking a walk by her farm, noticed that one row of her cornfield wasn't very beautiful due to the uneven heights of the corn stalks. To improve the aesthetics of the cornfield, she devised a data structure problem.
You are given a sequence of length and queries. Each query is one of four types, identified by an operation number:
-
Query type 1: Given an interval and an integer , determine if you can choose two (not necessarily distinct) numbers from the interval such that their difference is (x) (i.e. if there exists and in the interval with (b - a = x)).
-
Query type 2: Given an interval and an integer , determine if you can choose two numbers such that their sum is (x) (i.e. ). Note that if (x) is even, selecting the same element twice is allowed if (2a = x).
-
Query type 3: Given an interval and an integer , determine if you can choose two numbers whose product is (x) (i.e. ). Again, the same element may be chosen twice.
-
Query type 4: Given an interval and an integer , determine if you can choose two numbers (with the divisor non-zero) such that the quotient is (x) (i.e. , where the division has no remainder). Note that if (x=1) then any nonzero element chosen twice satisfies the condition; also, for (x=0), you must have and .
For each query, print YES
if such a pair exists, otherwise print NO
.
inputFormat
The first line contains two integers and , denoting the length of the sequence and the number of queries, respectively.
The second line contains integers representing the sequence .
Each of the next lines contains four integers: , , , and , representing the query type and its parameters.
outputFormat
For each query, print a single line containing YES
if there exists a pair of numbers in the specified interval satisfying the condition for that query, otherwise print NO
.
sample
5 5
1 2 3 4 5
1 1 5 2
2 1 5 5
3 1 3 6
4 2 4 1
4 1 5 2
YES
YES
YES
YES
YES
</p>