#K71292. Distinct Flower Types in a Garden

    ID: 33499 Type: Default 1000ms 256MiB

Distinct Flower Types in a Garden

Distinct Flower Types in a Garden

You are given a garden represented as a linear array of n flower beds. Initially, each flower bed contains a flower of a certain type. You will be given m update operations and q query operations combined in a total of m+q operations.

An update operation is represented as 1 i x, which means that the flower type in the i-th flower bed is changed to type x.

A query operation is represented as 2 l r, asking you to compute the number of distinct flower types in the range of beds from l to r (1-indexed).

The task is to process all operations in the given order and output the answer for each query operation.

Mathematically, if we denote the flower bed configuration as an array F, then a query operation on the interval \( [l,r] \) requires you to compute:

\( \text{ans} = |\{ F_i : l \le i \le r \}| \)

where \(|\cdot|\) denotes the cardinality of the set.

inputFormat

The input is given via stdin and has the following format:

  • The first line contains three integers: n, m, and q, representing the number of flower beds, update operations, and query operations respectively.
  • The second line contains n integers, where each integer represents the initial flower type present in the corresponding bed.
  • The next m+q lines each contain an operation in one of the following formats:
    • 1 i x — update operation: change the flower in the i-th bed to x.
    • 2 l r — query operation: output the number of distinct flower types in the beds from l to r.

outputFormat

For each query operation (i.e. operations starting with 2), output the answer on a new line to stdout.

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

4 3

</p>