#K66522. Distinct Element Counter
Distinct Element Counter
Distinct Element Counter
You are given an array of integers and a series of queries. There are two types of queries:
- Type 1: Query of the form
1 l r
requires you to output the number of distinct elements in the subarray \(a[l \ldots r]\) (using 1-based indexing). Here, \(1 \leq l \leq r \leq n\). - Type 2: Query of the form
2 i x
requires you to update the element at index \(i\) to \(x\) (also 1-based indexing).
Process all the queries in the order given. For each query of type 1, output the corresponding answer on a new line.
inputFormat
The input is given via standard input (stdin) in the following format:
- An integer \(n\) representing the number of elements in the array.
- A line with \(n\) space-separated integers representing the array \(a\).
- An integer \(q\) representing the number of queries.
- \(q\) lines follow, each containing three integers. The first integer of a line is the type of the query. If it is 1, then it is followed by two integers \(l\) and \(r\). If it is 2, it is followed by two integers \(i\) and \(x\).
outputFormat
For each query of type 1, print the number of distinct elements in the specified subarray. Each result should be printed on a new line in the order the queries appear.
## sample5
1 2 1 3 2
4
1 1 3
1 2 4
2 3 3
1 1 3
2
3
3
</p>