CF1619H Permutation and Queries
题目描述
给定由 $1 \sim n$ 构成的排列 $p$,有两种操作:
- `1 x y`:交换 $p_{x}$ 和 $p_{y}$。
- `2 i k`:给出 $i$ 的初始值,令 $i \gets p_{i}$ 执行 $k$ 次,最后输出 $i$。
至少有一个第二类操作。
输入格式
第一行包含两个整数 $n, q$($1 \le n,q \le 10^{5}$),分别表示数的个数和操作次数。
第二行包含 $n$ 个整数 $p_{1}, p_{2}, \ldots, p_{n}$。
接下来的 $q$ 行每行包含三个整数,表示一种操作。
输出格式
每行一个整数,表示每一个第二类查询的结果。
说明/提示
In the first example $ p = \{5, 3, 4, 2, 1\} $ .
The first query is to print $ p_3 $ . The answer is $ 4 $ .
The second query is to print $ p_{p_1} $ . The answer is $ 1 $ .
The third query is to swap $ p_1 $ and $ p_3 $ . Now $ p = \{4, 3, 5, 2, 1\} $ .
The fourth query is to print $ p_{p_1} $ . The answer is $ 2 $ .