#include #include struct Seg{ int n; std::vector v; Seg(int n_) { n = 1; while (n < n_) { n *= 2; } v.assign(2*n-1, 1<<30); } void setVal(int k, int val) { k += n-1; v[k] = val; while (k > 0) { k = (k-1)/2; v[k] = std::min(v[2*k+1], v[2*k+2]); } } int query(int a, int b) { return query(0, n, a, b, 0); } int query(int l, int r, int a, int b, int k) { if (r <= a || b <= l) return 1<<30; else if (a <= l && r <= b) return v[k]; else { int lv = query(l, (l+r)/2, a, b, 2*k+1); int rv = query((l+r)/2, r, a, b, 2*k+2); return std::min(lv, rv); } } }; int main() { int N, Q; std::cin >> N >> Q; Seg seg(N); std::vector pos(N); for (int i = 0; i < N; ++i) { int a; std::cin >> a; --a; pos[a] = i; seg.setVal(i, a); } for (int i = 0; i < Q; ++i) { int t, l, r; std::cin >> t >> l >> r; --l; --r; if (t == 1) { int lv = seg.v[l+seg.n-1]; int rv = seg.v[r+seg.n-1]; seg.setVal(l, lv); seg.setVal(r, rv); pos[lv] = r; pos[rv] = l; } else { std::cout << 1 + pos[seg.query(l, r+1)] << std::endl; } } }