#include using namespace std; // #define LOCAL // 提出時はコメントアウト #define DEBUG_ typedef long long ll; const double EPS = 1e-9; const ll INF = ((1LL<<62)-(1LL<<31)); typedef vector vecl; typedef pair pairl; template using uset = unordered_set; template using mapv = map>; template using umap = unordered_map; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) (ll)x.size() ll llceil(ll a,ll b) { return (a+b-1)/b; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template vector> genarr(ll n, ll m, T init) { return vector>(n,vector(m,init)); } ///// DEBUG #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) templateistream&operator>>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateostream&operator<<(ostream&os,pair&pair_var){os<<"("<ostream&operator<<(ostream&os,vector&vec){os<<"{";for(int i=0;iostream&operator<<(ostream&os,map&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;} os<<"}";return os;} templateostream&operator<<(ostream&os,set&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;} os<<"}";return os;} templateostream&operator<<(ostream&os,uset&set_var){os<<"{";repi(itr,set_var){if(itr!=set_var.begin())os<<", "; os<<*itr;} os<<"}";return os;} templateostream&operator<<(ostream&os,umap&map_var){os<<"{";repi(itr,map_var){if(itr!=map_var.begin())os<<", "; os<<*itr;} os<<"}";return os;} void dump_func(){DUMPOUT<void dump_func(Head&&head,Tail&&...tail){DUMPOUT<0){DUMPOUT<<", ";} dump_func(std::move(tail)...);} #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// #ifndef DEBUG_ #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif // SegTree: https://atcoder.github.io/ac-library/document_ja/segtree.html // @param n `0 <= n` // @return minimum non-negative `x` s.t. `n <= 2**x` int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } // @param n `1 <= n` // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0` int bsf(unsigned int n) { #ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index; #else return __builtin_ctz(n); #endif } template struct segtree { public: segtree() : segtree(0) {} segtree(int n) : segtree(std::vector(n, e())) {} segtree(const std::vector& v) : _n(int(v.size())) { log = ceil_pow2(_n); size = 1 << log; d = std::vector(2 * size, e()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { // O(logn) assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) { // O(1) assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r) { // [l,r): O(logn) assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size; while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } // [0,n) template int max_right(int l) { // segtree上で二分探索 O(logn) return max_right(l, [](S x) { return f(x); }); } template int max_right(int l, F f) { // segtree上で二分探索 O(logn) assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template int min_left(int r) { // segtree上で二分探索 O(logn) return min_left(r, [](S x) { return f(x); }); } template int min_left(int r, F f) { // segtree上で二分探索 O(logn) assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; // (S,*): 結合律の成立と単位元の存在を満たせばOK // 交換律は必要ないので演算の向きを恣意的に決めてOK struct S { ll a; ll size; }; ll B = 1e9+10; #define val(x) (x/B) #define idx(x) (x%B) S op(S l, S r) { return {val(l.a) < val(r.a) ? l.a : r.a, l.size+r.size}; } // S * S S e() { return {B*B-1,0}; } // モノイドの単位元 int solve(ostringstream &cout) { #ifdef LOCAL ifstream in("../../input.txt"); cin.rdbuf(in.rdbuf()); #endif ll n,q; cin>>n>>q; segtree seg(1e6); rep(i,n) { ll x; cin>>x; seg.set(i,S{B*x+i,0}); } rep(_,q) { ll c,l,r; cin>>c>>l>>r; l--; if (c==1) { ll lv = seg.get(l).a, rv = seg.get(--r).a; lv = val(lv) * B + r, rv = val(rv) * B + l; seg.set(l,S{rv,0}), seg.set(r,S{lv,0}); } else { ll x = seg.prod(l,r).a; dump(l,r,val(x),idx(x),x); cout << idx(x) + 1 << endl; } } return 0; } int main() { ostringstream oss; int res = solve(oss); cout << oss.str(); return res; }