#include using namespace std; using ll = long long; const int INF = 1e9; template class SegTree{ private: int n; int m; int depth; T def; vector data; function calculate; function update; T rec(int l, int r, int node, int node_l, int node_r) { if (node_r <= l || node_l >= r) return def; if (node_l >= l && node_r <= r) return data[node]; int mid = (node_l + node_r) / 2; return calculate( rec(l, r, node * 2, node_l, mid), rec(l, r, node * 2 + 1, mid, node_r)); } void _show() { vector res(depth + 1); vector width(depth + 1); width[depth-1] = 3; for(int i = depth-2; i >= 0; i--)width[i] = width[i + 1] * 2 + 2; for(int i = 0; i < depth; i++) { int start = 1< a, T _def, function _calculate, function _update): def(_def), calculate(_calculate), update(_update) { m = a.size(); for (n = 1; n < (int) a.size(); n *= 2, depth++); data.resize(n * 2, def); for (int i = 0; i < (int) a.size(); i++) data[i + n] = a[i]; for (int i = n - 1; i >= 1; i--) data[i] = calculate(data[i * 2], data[i * 2 + 1]); } //区間取得 T get(int l,int r){ if(l == r)return def; return rec(l,r,1,0,n); } //一点更新 void assign(int index, T val){ index += n; data[index] = update(data[index], val); for(;index /= 2;) data[index] = calculate(data[index * 2],data[index * 2 + 1]); } void print() { cerr << "["; for(int i = 0; i < m; i++) { cerr << data[i + n] << (i != m - 1 ? "," : "]\n"); } } void show() { _show(); } T operator[] (int i){ return data[i + n]; } }; int main() { int n, q; cin >> n >> q; vector pos(n); vector a(n); for(int i = 0; i < n; i++)cin >> a[i],a[i]--,pos[a[i]] = i; SegTree tree(a, INF, [](int a, int b){return min(a,b);}, [](int a, int b){return b;}); for(int i = 0; i < q; i++) { int t, l, r; cin >> t >> l >> r; l--,r--; if(t == 1) { int lv = tree[l], rv = tree[r]; tree.assign(r, lv), tree.assign(l, rv); pos[lv] = r, pos[rv] = l; } else { cout << pos[tree.get(l, r + 1)]+1 << endl; } } }