#P5355. Cornfield Query Challenge

    ID: 18588 Type: Default 1000ms 256MiB

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 NN corn stalks. To improve the aesthetics of the cornfield, she devised a data structure problem.

You are given a sequence aa of length nn and mm queries. Each query is one of four types, identified by an operation number:

  1. Query type 1: Given an interval [L,R][L, R] and an integer xx, determine if you can choose two (not necessarily distinct) numbers from the interval such that their difference is (x) (i.e. if there exists aa and bb in the interval with (b - a = x)).

  2. Query type 2: Given an interval [L,R][L, R] and an integer xx, determine if you can choose two numbers such that their sum is (x) (i.e. a+b=xa + b = x). Note that if (x) is even, selecting the same element twice is allowed if (2a = x).

  3. Query type 3: Given an interval [L,R][L, R] and an integer xx, determine if you can choose two numbers whose product is (x) (i.e. a×b=xa\times b = x). Again, the same element may be chosen twice.

  4. Query type 4: Given an interval [L,R][L, R] and an integer xx, determine if you can choose two numbers (with the divisor non-zero) such that the quotient is (x) (i.e. a/b=xa/b = x, 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 a=0a=0 and b0b\neq0.

For each query, print YES if such a pair exists, otherwise print NO.

inputFormat

The first line contains two integers nn and mm, denoting the length of the sequence and the number of queries, respectively.

The second line contains nn integers representing the sequence aa.

Each of the next mm lines contains four integers: opop, LL, RR, and xx, 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>