#include #define _GLIBCXX_DEBUG #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using P = pair; using vi = vector; using vc = vector; using vb = vector; using vs = vector; using vll = vector; using vp = vector>; using vvi = vector>; using vvc = vector>; using vvll = vector>; template inline bool chmax(T &a, T b) { if (a inline bool chmin(T &a, T b) { if (b struct SegmentTree { using F = function; int n; vector data; T identity; F operation; F update; SegmentTree(T _identity, F _operation, F _update) : identity(_identity), operation(_operation), update(_update) {} void init(int _n) { n = 1; while (n < _n) n <<= 1; data.assign(n<<1, identity); } void build(const vector &v) { int _n = (int)v.size(); init(_n); for (int i = 0; i < _n; ++i) data[n+i] = v[i]; for (int i = n-1; i >= 0; --i) { data[i] = operation(data[i<<1|0], data[i<<1|1]); } } void set(int i, T x) { i += n; data[i] = update(data[i], x); while (i > 1) { i >>= 1; data[i] = operation(data[i<<1|0], data[i<<1|1]); } } T fold(int l, int r) { l += n; r += n; T resl = identity, resr = identity; while (l < r) { if (l & 1) resl = operation(resl, data[l++]); if (r & 1) resr = operation(data[--r], resr); l >>= 1; r >>= 1; } return operation(resl, resr); } T operator[](int i) { return data[n+i];} }; const int INF = 1001001001; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vp a(n); rep(i, n) { int x; cin >> x; a[i] = P(x, i); } auto operation = [](P a, P b) { return a.fi < b.fi ? a : b;}; auto update = [](P a, P b) { return b;}; SegmentTree

seg(P(INF, -1), operation, update); seg.build(a); while (q--) { int com, l, r; cin >> com >> l >> r; l--; r--; if (com == 1) { int tmpl = seg[l].fi, tmpr = seg[r].fi; seg.set(l, P(tmpr, l)); seg.set(r, P(tmpl, r)); } else { cout << seg.fold(l, r+1).se + 1 << endl; } } }