#P3201. [HNOI2009] 梦幻布丁

    ID: 2250 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2009线段树各省省选平衡树湖南枚举,暴力

[HNOI2009] 梦幻布丁

Description

There are nn puddings in a line, and we will perform mm operations. An operation may recolor all puddings of one color into another color, or ask how many color segments there are at the moment.

For example, four puddings with colors 1,2,2,11, 2, 2, 1 have 33 color segments.

Input Format

The first line contains two integers, the number of puddings nn and the number of operations mm.
The second line contains nn integers; the ii-th integer is the color aia_i of the ii-th pudding.
Then there are mm lines, each describing one operation. Each line starts with an integer opop indicating the type:

  • If op=1op = 1, then two integers x,yx, y follow, meaning recolor all puddings of color xx to color yy.
  • If op=2op = 2, it denotes a query.

Output Format

For each query, output one integer on a single line, indicating the answer.

4 3
1 2 2 1
2
1 2 1
2

3
1

Hint

Sample 1 Explanation
Initially the colors are 1,2,2,11, 2, 2, 1, and the three color segments are [1,1],[2,3],[4,4][1, 1], [2, 3], [4, 4].
After one operation, the colors become 1,1,1,11, 1, 1, 1, leaving only one segment [1,4][1, 4].

Constraints
For all test points, it is guaranteed that 1n,m1051 \leq n, m \leq 10^5, 1ai,x,y1061 \leq a_i, x, y \leq 10^6.

Notes
Please note that it is not guaranteed that color IDs are at most nn, it is also not guaranteed that xyx \neq y, and mm is not an upper bound on color IDs.

Translated by ChatGPT 5