#P1903. 【模板】带修莫队 / [国家集训队] 数颜色 / 维护队列
【模板】带修莫队 / [国家集训队] 数颜色 / 维护队列
Description
Momo bought a set of colored pens (some colors may be the same) and lined them up in a row. You need to answer Momo's requests. Momo will issue the following operations:
-
: Query how many distinct colors appear among the pens from the -th to the -th (inclusive).
-
: Replace the -th pen's color with .
To satisfy Momo's requests, can you process these operations?
Input Format
The first line contains two integers , , representing the initial number of pens and the number of operations, respectively.
The second line contains integers, where the -th integer is the color of the -th pen in the initial row.
From line to line , each line describes one operation; see the description above for the format.
Output Format
For each query operation, output a single integer on its own line: the number of distinct colors among the pens from the -th to the -th.
6 5
1 2 3 4 5 5
Q 1 4
Q 2 6
R 1 2
Q 1 4
Q 2 6
4
4
3
4
Hint
For 30% of the testdata, .
For 60% of the testdata, .
For all testdata, .
All integers appearing in the input are between and inclusive.
This problem may be slightly tight on constant factors.
Source: bzoj2120.
The testdata for this problem are created by Luogu, using CYaRon, and took 5 minutes to generate.
Translated by ChatGPT 5
京公网安备 11011102002149号