#include using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for(int i=0; ibool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b node; public: SegmentTree(vector v){ n = 1; while(n < v.size()) n *= 2; node.resize(2*n-1); for(int i = 0; i < v.size(); 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, 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]); } } int getmin(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = n; if(b <= l || r <= a) 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 main(){ int N, Q; cin >> N >> Q; vector A(N); map table; REP(i,N){ int a; cin >> a; A[i] = a; table[a] = i; } SegmentTree tree(A); REP(q, Q){ int a, l, r; cin >> a >> l >> r; l--, r--; if(a == 1){ tree.update(l, A[r]); tree.update(r, A[l]); swap(A[r], A[l]); int x = table[A[r]]; int y = table[A[l]]; table[A[r]] = y; table[A[l]] = x; } else if(a == 2){ int ans; ans = tree.getmin(l, r+1); cout << table[ans]+1 << endl; } } return 0; }