#P6688. Range Essence Equality Query

    ID: 19896 Type: Default 1000ms 256MiB

Range Essence Equality Query

Range Essence Equality Query

You are given a non-negative integer sequence \(a_1, a_2, \dots, a_n\) of length \(n\). There are \(q\) operations. For each operation, a parameter \(op\) is given first:

  • if \(op = 0\), two integers \(x\) and \(y\) follow, and you need to update \(a_x = y\).
  • if \(op = 1\), four integers \(l_1, r_1, l_2, r_2\) are given (with the guarantee that \(r_1 - l_1 = r_2 - l_2\)). For this query, you have to determine whether the subarray \(a[l_1 \dots r_1]\) and the subarray \(a[l_2 \dots r_2]\) are essentially equal.

The definition of essentially equal is as follows: Let the length of each interval be \(\text{len}\). Let \(p_1, p_2, \dots, p_{\text{len}}\) be the sorted (in ascending order) values of the subarray \(a[l_1 \dots r_1]\), and \(q_1, q_2, \dots, q_{\text{len}}\) be the sorted values of the subarray \(a[l_2 \dots r_2]\). The two subarrays are essentially equal if and only if there exists an integer \(k\) such that \[ \forall i,\; p_i + k = q_i. \] Otherwise, they are not essentially equal.

inputFormat

The first line contains two integers \(n\) and \(q\) representing the length of the sequence and the number of operations, respectively.

The second line contains \(n\) non-negative integers: \(a_1, a_2, \dots, a_n\).

The following \(q\) lines each represent an operation. For an operation:

  • If the first integer is 0, it is followed by two integers \(x\) and \(y\), indicating an update operation \(a_x = y\).
  • If the first integer is 1, it is followed by four integers \(l_1, r_1, l_2, r_2\) (with \(r_1 - l_1 = r_2 - l_2\)) representing a query operation.

outputFormat

For each query operation (where \(op = 1\)), output a single line containing "YES" if the two intervals are essentially equal, or "NO" otherwise.

sample

5 4
1 2 3 4 5
1 1 3 3 5
0 3 10
1 1 3 3 5
1 1 5 1 5
YES

NO YES

</p>