#include using namespace std; using ll = long long; // #define int ll using PII = pair; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template T &chmin(T &a, const T &b) { return a = min(a, b); } template T &chmax(T &a, const T &b) { return a = max(a, b); } template bool IN(T a, T b, T x) { return a<=x&&x T ceil(T a, T b) { return a/b + !!(a%b); } template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a,Ts... ts) { return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value==0>::type fill_v(T &t, const V &v) { t=v; } template typename enable_if::value!=0>::type fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); } template ostream &operator <<(ostream& out,const pair& a) { out<<'('< ostream &operator <<(ostream& out,const vector& a){ out<<'['; for(const T &i: a) out< ostream &operator <<(ostream& out, const set& a) { out<<'{'; for(const T &i: a) out< ostream &operator <<(ostream& out, const map& a) { out<<'{'; for(auto &i: a) out< struct segtree { using T = typename Monoid::T; int n; vector dat; segtree(int n_) { n = 1; while(n < n_) n <<= 1; dat.assign(n*2, Monoid::id()); } void build(vector v) { REP(i, v.size()) dat[i+n] = v[i]; for(int i=n-1; i>0; --i) dat[i] = Monoid::op(dat[i*2], dat[i*2+1]); } T query(int a, int b) { T l = Monoid::id(), r = Monoid::id(); for(a+=n, b+=n; a>=1, b>>=1) { if(a&1) l = Monoid::op(l, dat[a++]); if(b&1) r = Monoid::op(dat[--b], r); } return Monoid::op(l, r); } void update(int i, T v) { i += n; dat[i] = v; while(i >>= 1) { dat[i] = Monoid::op(dat[i*2], dat[i*2+1]); } } friend ostream &operator <<(ostream& out,const segtree& seg){ out << "---------------------" << endl; int cnt = 1; for(int i=1; i<=seg.n; i*=2) { REP(j, i) { out << seg.dat[cnt] << " "; cnt++; } out << endl; } out << "---------------------" << endl; return out; } }; template struct min_monoid { using T = Tp; static constexpr Tp id() { return PII(LLINF, LLINF); } static Tp op(const Tp &a, const Tp &b) { return min(a, b); } }; template struct max_monoid { using T = Tp; static constexpr Tp id() { return -LLINF; } static Tp op(const Tp &a, const Tp &b) { return max(a, b); } }; template struct sum_monoid { using T = Tp; static constexpr Tp id() { return 0; } static Tp op(const Tp &a, const Tp &b) { return a+b; } }; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, q; cin >> n >> q; vector a(n); REP(i, n) cin >> a[i].first, a[i].second = i; segtree> seg(n); seg.build(a); while(q--) { ll t, l, r; cin >> t >> l >> r; l--, r--; if(t == 1) { PII al = seg.query(l, l+1), ar = seg.query(r, r+1); seg.update(l, PII{ar.first, l}); seg.update(r, PII{al.first, r}); } else { cout << seg.query(l, r+1).second+1 << endl; } // cout << seg << endl; } return 0; }