AtCoder Beginner Contest 183
F
Confluence
AtCoder
⌀ 1586
原题
← E→
翻译中…

Problem Statement

翻译中…

$N$ students are about to go to school. Student $i$ belongs to Class $C_i$.

翻译中…

After leaving home, each student will head to school while repeatedly joining up with a group of other students. Once students join up with each other, they will not separate.

翻译中…

You will be given $Q$ queries that should be processed in order. There are two kinds of queries, in the following formats, that mean the following:

翻译中…
  • 1 a b: The group containing Student $a$ and the group containing Student $b$ merges. (If they are already in the same group, nothing happens.)
  • 2 x y: You are asked to find the number of students belonging to Class $y$ who are already in the same group as Student $x$ (including Student $x$) at the time of this query.
翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq Q \leq 2 \times 10^5$
  • $1 \leq C_i,a,b,x,y \leq N$
  • In a query in the format 1 a b, $a \neq b$.
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N Q
C_1 \ldots C_N
Query_1
\vdots
Query_Q

翻译中…

Output

翻译中…

Print the answers to the queries in the format 2 x y, each in its own line, in order.

翻译中…

样例

Input #1
5 5
1 2 3 2 1
1 1 2
1 2 5
2 1 1
1 3 4
2 3 4
Output #1
2
0
At the time of the $3$-rd query, Student $1$ has joined up with Student $2$ and $5$. Among these three students, two belong to Class $1$. At the time of the $5$-th query, Student $3$ has joined up with Student $4$. Among these two students, none belongs to Class $4$.
Input #2
5 4
2 2 2 2 2
1 1 2
1 1 3
1 2 3
2 2 2
Output #2
3
There may be queries in the format `1 a b` for students who already belong to the same group.
Input #3
12 9
1 2 3 1 2 3 1 2 3 1 2 3
1 1 2
1 3 4
1 5 6
1 7 8
2 2 1
1 9 10
2 5 6
1 4 8
2 6 1
Output #3
1
0
0
题目信息
题号
abc183_f
时间限制
3 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。