PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000052. Hoán vị và truy vấn (Permutation and Queries)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hoán vị và truy vấn (Permutation and Queries)
Permutation and Queries
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a permutation of , process two operation types:
1 x y: swap the values and , yielding a new permutation.2 i k: start with , repeat the assignment exactly times, and print the resulting .
Every query uses the current permutation, not the original one.
Input
The first line contains , followed by the permutation. Each of the lines is 1 x y () or 2 i k (). At least one type-2 query is guaranteed.
Output
Print the final for each type-2 query.
Subtasks
- Subtask 1 (10 points): ; . The initial array is a permutation of .
- Subtask 2 (20 points): ; . The initial array is a permutation of .
- Subtask 3 (25 points): ; . The initial array is a permutation of .
- Subtask 4 (45 points): ; . The initial array is a permutation of .
Examples
Input
5 4
5 3 4 2 1
2 3 1
2 1 2
1 1 3
2 1 2
Output
4
1
2
Explanation
Initially . One step from reaches ; two steps from reach then . After swapping and , the permutation is ; two steps from go , giving 2.