#include #define REP(i, n) for(int i = 0;i < n;i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long using namespace std; typedef pair P; typedef pair LP; typedef pair PP; typedef pair LPP; typedef vectorvec; typedef vector mat; typedef vector> Graph; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1000000000; const ll LINF = 1000000000000000000;//1e18 const ll MOD = 1000000007; const double PI = acos(-1.0); const double EPS = 1e-10; 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 inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;}; struct valueIdx{ ll value, idx; }; template class SegTree{ int n; //葉の数 vector data; //データを格納するvector T def; //初期値かつ単位元 function operation; //区間クエリで使う処理 function update; //点更新で使う処理 T _query(int a, int b, int k, int l, int r){ if(r <= a || b <= l) return def; if(a <= l && r <= b) return data[k]; else{ T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: //_n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, _update:更新関数 SegTree(size_t _n, T _def, function _operation, function _update) : def(_def), operation(_operation), update(_update){ n = 1; while(n < _n){ n *= 2; } data = vector (2 * n - 1, def); } void change(int i, T x){ i += n - 1; data[i] = update(data[i], x); while(i > 0){ i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } //[a, b)の区間クエリ T query(int a, int b){ return _query(a, b, 0, 0, n); } T operator[](int i){ return data[i + n - 1]; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; SegTree st(N, valueIdx{INF,0}, [](valueIdx a, valueIdx b){return (a.value < b.value ? a : b);}, [](valueIdx a, valueIdx b){return b;} ); REP(i,N){ int a; cin >> a; st.change(i, {a,i+1}); } REP(i,Q){ int q, l, r; cin >> q >> l >> r; --l, --r; if(q==1){ auto L = st.query(l, l + 1).value; auto R = st.query(r, r + 1).value; st.change(l, {R,l+1}); st.change(r, {L,r+1}); } else cout << st.query(l, r + 1).idx << endl; } }