#ds801. 梦幻布丁

梦幻布丁

Dream Pudding

Problem Source

HNOI2009

Problem Description

There are nn puddings placed in a row, and mm operations are performed. Each operation turns all the puddings of one colour into another colour, and then asks how many colour segments there are in total at the moment.

For example, four puddings with colours 1,2,2,11, 2, 2, 1 form 33 colour segments in total.

Input Format

The first line contains two integers n,m (1≤n,m≤105)n, m\ (1 \le n, m \le 10^5), the number of puddings and the number of operations.

The second line contains nn integers a1,a2,…,an (1≤ai≤106)a_1, a_2, \dots, a_n\ (1 \le a_i \le 10^6), the colour of the ii-th pudding.

The following mm lines describe one operation each. Each line begins with an integer opop indicating the operation type:

  • If op=1op = 1, then two integers x,yx, y follow, meaning change all puddings of colour xx into colour yy. It is guaranteed that 1≤x,y≤1061 \le x, y \le 10^6, and xx may equal yy.
  • If op=2op = 2, it means a query.

Output Format

For each operation of the second type (a query), output in order how many colour segments there are at that moment.

Sample Input

4 3
1 2 2 1
2
1 2 1
2

Sample Output

3
1