QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 100

#16218. Dream Pudding

Estadísticas

One day, Xiao Xu's friend invited him to eat pudding, so Xiao Xu happily went to his friend's house. Wow! So many colorful puddings! The friend said, "Let's play a game before we start eating." He arranged the puddings in a row and continued, "I can change all puddings of a certain color to another color, and at certain moments, I will ask you how many color segments there are in total. For example, four puddings with colors 1, 2, 2, 1 have a total of 3 color segments."

Input

The first line contains two integers $n$ and $m$, representing the number of puddings and the number of operations, respectively, separated by a space. The second line contains $n$ integers $A_1, A_2, \cdots, A_n$ separated by spaces, where $A_i(1 \le i \le n)$ represents the color of the $i$-th pudding. The following $m$ lines describe the $m$ operations. For each operation, if the first number is $1$, it means the friend wants to change colors; this is followed by two integers $x$ and $y$ ($x$ may equal $y$), meaning that after the operation, all puddings with color $x$ are changed to color $y$. If the first number is $2$, it means the friend wants to ask how many color segments there are currently, and you should output an integer as the answer. The input data guarantees $0 < n, m < 100\,001$ and $0 < A_i, x, y < 1\,000\,000$.

Output

The number of lines in the output corresponds to the number of type 2 operations (i.e., queries about the number of color segments). For each query, output the number of color segments at that time on a new line.

Examples

Input 1

4 3
1 2 2 1
2
1 2 1
2

Output 1

3
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.