#P1903. 【模板】带修莫队 / [国家集训队] 数颜色 / 维护队列

    ID: 854 远端评测题 1500~2500ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>莫队WC/CTSC/集训队O2优化块状链表,块状数组,分块

【模板】带修莫队 / [国家集训队] 数颜色 / 维护队列

Description

Momo bought a set of NN 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:

  1. Q L RQ\ L\ R: Query how many distinct colors appear among the pens from the LL-th to the RR-th (inclusive).

  2. R P CR\ P\ C: Replace the PP-th pen's color with CC.

To satisfy Momo's requests, can you process these operations?

Input Format

The first line contains two integers NN, MM, representing the initial number of pens and the number of operations, respectively.

The second line contains NN integers, where the ii-th integer is the color of the ii-th pen in the initial row.

From line 33 to line 2+M2+M, 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 LL-th to the RR-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, n,m10000n,m \leq 10000.

For 60% of the testdata, n,m50000n,m \leq 50000.

For all testdata, n,m133333n,m \leq 133333.

All integers appearing in the input are between 11 and 10610^6 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