#K35132. Distinct Elements in Subarrays

    ID: 25464 Type: Default 1000ms 256MiB

Distinct Elements in Subarrays

Distinct Elements in Subarrays

You are given an array of integers and are required to perform a series of operations on it. There are three types of operations:

  • Update Operation: "1 index value" – Update the element at the given index (1-indexed) to the given value.
  • Query Operation: "2 l r" – Calculate and output the number of distinct elements in the subarray from index l to r (inclusive). In mathematical notation, if the array is \(a_1, a_2, \ldots, a_n\), then for a query \(2\ l\ r\), you must output \(\left|\{a_l, a_{l+1}, \ldots, a_r\}\right|\).
  • Replace Operation: "3 y" – Replace every element \(a_i\) in the array with \(\min(a_i, y)\). That is, if \(a_i \ge y\), then set \(a_i = y\); otherwise, leave it unchanged.

Your task is to implement these operations. Only the Query operations produce an output, each on a new line. The operations are given sequentially and the changes made by earlier operations affect later ones.

inputFormat

The first line contains two integers \(N\) and \(Q\), where \(N\) is the number of elements in the array and \(Q\) is the number of operations. The second line contains \(N\) integers representing the initial array. Each of the next \(Q\) lines contains one operation in one of the following formats:

  • 1 index value
  • 2 l r
  • 3 y

All operations are to be processed in the order they are given. Input is provided via standard input (stdin).

outputFormat

For each Query operation (type 2), output the result (i.e. the number of distinct elements in the specified subarray) on a new line to standard output (stdout).

## sample
5 5
1 2 1 3 2
2 1 5
1 3 4
2 1 5
3 2
2 2 4
3

4 1

</p>