#include using namespace std; template class segtree{ Tp *tree; Tp (*operation)(const Tp&, const Tp&); Tp ident; size_t len, depth; public: segtree(size_t n, Tp (*op)(const Tp&, const Tp&), Tp id=0) : operation(op), ident(id){ for(depth=1;(1ULL<>1;p>0;p>>=1){ tree[p] = operation(tree[2*p], tree[2*p+1]); } } void add(size_t pos, Tp val){ tree[len+pos] += val; for(size_t p=(len+pos)>>1;p>0;p>>=1){ tree[p] = operation(tree[2*p], tree[2*p+1]); } } Tp queue(size_t left, size_t right){ Tp lval = ident, rval = ident; left += len; right += len; while(true){ if(left >= right) return operation(lval, rval); if(right - left == 1) return operation(lval, operation(tree[left], rval)); if(left & 1) lval = operation(lval, tree[left++]); left >>= 1; if(right & 1) rval = operation(tree[right-1], rval); right >>= 1; } } Tp &operator[](size_t pos){ return tree[len+pos]; } void refresh(){ for(size_t p=len-1;p>0;--p){ tree[p] = operation(tree[2*p], tree[2*p+1]); } } }; int main(){ int N, Q; int t, l, r; cin >> N >> Q; segtree> st(N, [](auto x, auto y){ return min(x, y); }, {N+1, -1}); for(int i=0;i> a; st[i] = {a, i+1}; } st.refresh(); for(int i=0;i> t >> l >> r; if(t==1){ int tmp = st[l-1].first; st.update(l-1, {st[r-1].first, st[l-1].second}); st.update(r-1, {tmp, st[r-1].second}); } else cout << st.queue(l-1, r).second << endl; } return 0; }