#P3792. Contiguous Range Query and Update
Contiguous Range Query and Update
Contiguous Range Query and Update
You are given a sequence a of length n. You need to perform q operations, which are of two types:
- Update: Change the value at position x to y.
- Query: Check whether the subsequence in the interval [l, r] can be rearranged to form a contiguous segment of distinct integers.
A subsequence can be rearranged to form a contiguous segment if and only if all the numbers are distinct and if max - min = r - l (using 1-indexed positions), where max and min denote the maximum and minimum values in the interval, respectively. For example, the segment 1 2 2 3
is invalid due to duplicate numbers, while 4 2 3 1
is valid because when rearranged it becomes 1 2 3 4
, which is a contiguous range.
Input and Output Formats are described below.
inputFormat
The first line contains two integers n and q (1 ≤ n, q ≤ 10^5
in general, though the constraints for this problem may be smaller).
The second line contains n integers, representing the initial sequence a (1-indexed).
Each of the next q lines describes an operation in one of the following formats:
1 x y
— update the value at position x to y.2 l r
— query whether the subarray from l to r (inclusive) can be rearranged to form a contiguous segment of integers.
outputFormat
For each query operation (operation of type 2
), output a single line containing Yes
if the segment can be rearranged into a contiguous range, or No
otherwise.
sample
5 5
4 2 1 3 9
2 1 4
2 2 5
1 5 5
2 2 5
2 1 5
Yes
No
No
Yes
</p>