#include #include #include #define rep(i, n) for(i = 0; i < (n); i++) using namespace std; typedef pair P; const int INF = 1145141919; const int DEPTH = 17; struct SegTree { P d[1 << (DEPTH + 1)]; //(val, pos) SegTree() { int i; rep(i, 1 << (DEPTH + 1)) d[i] = P(0, 0); } void update(int pos, int x) { pos += (1 << DEPTH) - 1; d[pos] = P(x, pos - (1 << DEPTH) + 1); while (pos > 0) { pos = (pos - 1) / 2; d[pos] = min(d[pos * 2 + 1], d[pos * 2 + 2]); } } P query(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) { if (a >= r || b <= l) return P(INF, -1); if (l <= a && b <= r) return d[id]; P u = query(l, r, a, (a + b) / 2, id * 2 + 1); P v = query(l, r, (a + b) / 2, b, id * 2 + 2); return min(u, v); } }; int n, q; int a[100000]; int type, l, r; SegTree seg; signed main() { int i; cin >> n >> q; rep(i, n) cin >> a[i]; rep(i, n) seg.update(i, a[i]); rep(i, q) { cin >> type >> l >> r; l--; r--; if (type == 1) { seg.update(l, a[r]); seg.update(r, a[l]); swap(a[l], a[r]); } else { P res = seg.query(l, r + 1); cout << res.second + 1 << endl; } } return 0; }