#include #include #include #include #include using namespace std; typedef long long int ll; int const INF=INT_MAX; struct SegmentTree{ private: int n; vector node; public: SegmentTree(vector v){ int sz=v.size(); n=1; while(n=0;i--){ node[i]=min(node[2*i+1],node[2*i+2]); } } void update(int x,int val){ //最下段のノードにアクセスする x+=(n-1); node[x]=val; while(x>0){ x=(x-1)/2; node[x]=min(node[2*x+1],node[2*x+2]); } } void add(int x,int val){ x+=(n-1); node[x]+=val; while(x>0){ x=(x-1)/2; node[x]=node[2*x+1]+node[2*x+2]; } } int getmin(int a,int b,int k=0,int l=0,int r=-1){ if(r<0)r=n; if(r<=a||b<=l)return INF; if(a<=l&&r<=b) return node[k]; int vl=getmin(a,b,2*k+1,l,(l+r)/2); int vr=getmin(a,b,2*k+2,(l+r)/2,r); return min(vl,vr); } int getsum(int a,int b,int k=0,int l=0,int r=-1){ if(r<0)r=n; if(b<=l||r<=a)return 0; if(a<=l&&r<=b)return node[k]; int vl=getsum(a,b,2*k+1,l,(l+r)/2); int vr=getsum(a,b,2*k+2,(l+r)/2,r); return vl+vr; } }; int main(){ int n,q; cin >> n >> q; vector v(n),p(n); for(int i=0;i> v[i]; p[v[i]]=i+1; } SegmentTree seg(v); for(int i=0;i> c >> x >> y; if(c==1){ int cp=v[x-1],cp2=v[y-1]; v[y-1]=cp,v[x-1]=cp2; p[cp2]=x,p[cp]=y; seg.update(x-1,cp2); seg.update(y-1,cp); } else{ cout << p[seg.getmin(x-1,y)] << endl; } } }