#K95397. Distinct Elements in Subarray Queries

    ID: 38854 Type: Default 1000ms 256MiB

Distinct Elements in Subarray Queries

Distinct Elements in Subarray Queries

You are given an array of integers of length \(n\) and \(q\) queries. There are two types of queries:

  • Type 1: 1 L R — Query the number of distinct elements in the subarray \(A[L \ldots R]\) (1-indexed).
  • Type 2: 2 L X — Update the element at index \(L\) to \(X\).

For each type 1 query, output the number of distinct elements in the specified subarray. Use \(\LaTeX\) format for any formulas.


Example:

Input:
6 5
1 1 2 3 4 2
1 1 3
1 2 4
2 3 5
1 1 3
1 3 6

Output: 2 3 2 4

</p>

inputFormat

The first line contains two integers \(n\) and \(q\) denoting the number of elements and the number of queries, respectively.

The second line contains \(n\) space-separated integers representing the array \(A\).

The following \(q\) lines contain the queries. Each query is given in one of the following formats:

  • 1 L R for a type 1 query (output the distinct element count in \(A[L...R]\)).
  • 2 L X for a type 2 query (update the element at \(L\) to \(X\)).

All indices follow 1-indexing.

outputFormat

For each type 1 query, output a single line containing the number of distinct elements in the specified subarray.

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

3 2 4

</p>