#P3674. Query Sequence Operations

    ID: 16925 Type: Default 1000ms 256MiB

Query Sequence Operations

Query Sequence Operations

Given a sequence \(a\) of length \(n\), there are \(m\) queries. Each query specifies an operation on a segment of the sequence. There are three types of queries:

  • Type 1: Given a range \([L,R]\) and an integer \(x\), determine whether it is possible to choose two numbers from the subarray such that their difference equals \(x\), i.e. \(a_i - a_j = x\) for some indices \(i,j\) (you are allowed to choose the same position twice).
  • Type 2: Given a range \([L,R]\) and an integer \(x\), determine whether it is possible to choose two numbers from the subarray such that their sum equals \(x\), i.e. \(a_i + a_j = x\) for some indices \(i,j\) (the same index may be used twice).
  • Type 3: Given a range \([L,R]\) and an integer \(x\), determine whether it is possible to choose two numbers from the subarray such that their product equals \(x\), i.e. \(a_i \times a_j = x\) for some indices \(i,j\) (again, the same index may be chosen twice).

Output Yes if such a pair exists, otherwise output No.

inputFormat

The first line contains two integers \(n\) and \(m\) representing the length of the sequence and the number of queries respectively.

The second line contains \(n\) space-separated integers denoting the sequence \(a\).

Then there are \(m\) lines, each containing four integers \(t\), \(L\), \(R\), and \(x\), where \(t\) indicates the type of query (1 for difference, 2 for sum, 3 for product), \(L\) and \(R\) specify the range, and \(x\) is the target value.

outputFormat

For each query, output a single line containing either Yes or No depending on whether it is possible to select two numbers (possibly the same element twice) within the specified range that satisfy the given condition.

sample

5 5
1 2 3 4 5
1 1 5 1
2 1 3 5
3 2 4 8
2 4 5 10
3 1 1 2
Yes

Yes Yes Yes No

</p>