#include using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() typedef long long LL; typedef pair P; const LL mod=1000000007; const LL LINF=1LL<<62; const int INF=1<<30; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; template struct SegmentTree{ private: int n; vector node; public: SegmentTree(vector v){ int sz = v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1,mp(INF,INF)); for (int i = 0; i < sz; i++) node[i+n-1] = v[i]; for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]); } void update(int x,T 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]); } } T 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 mp(INF,INF); if(a <= l && r <= b) return node[k]; T vl = getmin(a, b, 2*k+1, l , (l+r)/2); T vr = getmin(a, b, 2*k+2, (l+r)/2,r); return min(vl, vr); } }; int main(){ int n,q;cin >> n >> q; vector

v(n); for (int i = 0; i < n; i++) { cin >> v[i].fs; v[i].sc = i; } SegmentTree

seg(v); while(q--){ int t,l,r;cin >> t >> l >> r; if(t == 1){ l--,r--; auto p = seg.getmin(l,l+1); seg.update(l, mp(seg.getmin(r,r+1).fs,l)); seg.update(r, mp(p.fs, r)); } else{ l--; cout << seg.getmin(l, r).sc + 1 << endl; } } return 0; }