#include #include #include #include using namespace std; template class SegmentTree{ private: using F = function; int sz; vector seg; const F op;//演算 const Monoid e;//単位元 public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] = x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } Monoid operator[](const int &k)const{ return seg[k+sz]; } }; int main(){ int N,Q; cin >> N >> Q; SegmentTree seg(N,[](int a,int b){return min(a,b);},1e9); vector p(N); for(int i=0;i> a; a--; p[a] = i; seg.set(i,a); } seg.build(); for(int q=0;q> c >> l >> r; if(c==1){ l--; r--; swap(p[seg[l]],p[seg[r]]); int a = seg[l]; seg.update(l,seg[r]); seg.update(r,a); }else{ l--; r--; cout << p[seg.query(l,r+1)]+1 << endl; } } }