#P1903. Distinct Colors Query
Distinct Colors Query
Distinct Colors Query
墨墨 has purchased \(N\) colored brushes arranged in a row. You are given two types of operations:
- Query Operation: \(Q\ L\ R\) - For brushes between positions \(L\) and \(R\) (inclusive), output the number of distinct colors.
- Update Operation: \(R\ P\ C\) - Replace the brush at position \(P\) with color \(C\).
Positions are 1-indexed. The input begins with two integers, followed by the initial list of brush colors and then \(Q\) operations. For each query operation, output its result on a separate line.
inputFormat
The first line contains two integers \(N\) and \(Q\), representing the number of brushes and the number of operations, respectively.
The second line contains \(N\) integers, indicating the initial colors of the brushes.
The next \(Q\) lines each contain an operation in one of the following formats:
Q L R
R P C
outputFormat
For each query operation \(Q L R\), output one integer on a new line indicating the number of distinct colors in the specified range.
sample
5 5
1 2 3 2 1
Q 1 5
R 3 2
Q 1 5
R 1 3
Q 2 4
3
2
1
</p>