#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; template struct SegmentTree { private: using Func = function; const Func F; const Monoid UNITY; int n; vector> node; public: //m=size, f=[](M a,M b){return ;} SegmentTree(int m, const Func f, const Monoid &unity) : F(f), UNITY(unity) { n = 1; while (n < m) n <<= 1; node.resize(n * 2 - 1, {UNITY,-1}); } SegmentTree(const vector& v, const Func f, const Monoid &unity) : F(f), UNITY(unity) { int sz = v.size(); n = 1; while (n < sz) n <<= 1; node.resize(n * 2 - 1, {UNITY,-1}); REP(i, sz) node[i + n - 1] = {v[i],i}; REPR(i, n - 2) { if (node[2 * i + 1].first < node[2 * i + 2].first) { node[i] = node[2 * i + 1]; } else { node[i] = node[2 * i + 2]; } } } void update(int x, int val) { if (x >= n || x < 0) return; x += n - 1; node[x].first = val; while (x > 0) { x = (x - 1) >> 1; if (node[2 * x + 1].first < node[2 * x + 2].first) { node[x] = node[2 * x + 1]; } else { node[x] = node[2 * x + 2]; } } } // [a,b) pair get(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return {UNITY,-1}; if (a <= l && r <= b) return node[k]; pair vl = get(a, b, 2 * k + 1, l, (r - l) / 2 + l); pair vr = get(a, b, 2 * k + 2, (r - l) / 2 + l, r); if (vl.first < vr.first) { return vl; } else { return vr; } } }; int main() { int n, q; cin >> n >> q; vector a(n); REP(i, n) cin >> a[i]; SegmentTree seg(a, [](int a, int b) {return min(a, b); }, INF); REP(i, q) { int t, l, r; cin >> t >> l >> r; l--; r--; if (t == 1) { seg.update(l, a[r]); seg.update(r, a[l]); swap(a[l], a[r]); } else { cout << seg.get(l, r + 1).second+1 << endl; } } getchar(); getchar(); }