#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class MinSegmentTree { std::vector> vec; int inner_min(int depth, int from, int until) const { if (from == until) return INT_MAX; int length = 1 << depth; int mid = (from + length - 1) / length * length; if (from <= mid && mid + length <= until) { return std::min({ vec[depth][mid / length], inner_min(depth, from, mid), inner_min(depth, mid + length, until) }); } else { return std::min(inner_min(depth - 1, from, mid), inner_min(depth - 1, mid, until)); } } public: MinSegmentTree(const std::vector& initial) : vec{ initial } { while (vec.back().size() != 1) { vec.emplace_back((vec.back().size() + 1) / 2); } for (auto i = 1; i < vec.size(); ++i) { for (auto j = 0; j < vec[i].size(); ++j) { if (j * 2 + 1 < vec[i - 1].size()) { vec[i][j] = std::min(vec[i - 1][j * 2 + 1], vec[i - 1][j * 2]); } else { vec[i][j] = vec[i - 1][j * 2]; } } } } int min_of(int from, int until) const { return inner_min(vec.size() - 1, from, until); } void update(int position, int value) { vec[0][position] = value; for (auto i = 1; i < vec.size(); ++i) { position >>= 1; if (position * 2 + 1 < vec[i - 1].size()) { vec[i][position] = std::min(vec[i - 1][position * 2], vec[i - 1][position * 2 + 1]); } else { vec[i][position] = vec[i - 1][position * 2]; } } } }; int main() { int n, q; std::cin >> n >> q; std::vector initial(n); for (auto& a : initial) std::cin >> a; std::vector indices(n); for (auto i = 0; i < n; ++i) indices[i] = i; std::sort(indices.begin(), indices.end(), [&initial](const int a, const int b) {return initial[a] < initial[b]; }); MinSegmentTree seg(initial); for (auto i = 0; i < q; ++i) { int t, l, r; std::cin >> t >> l >> r; --l; --r; if (t == 1) { seg.update(l, initial[r]); seg.update(r, initial[l]); auto temp = indices[initial[r] - 1]; indices[initial[r] - 1] = indices[initial[l] - 1]; indices[initial[l] - 1] = temp; temp = initial[r]; initial[r] = initial[l]; initial[l] = temp; } else { std::cout << indices[seg.min_of(l, r + 1) - 1] + 1 << std::endl; } } }