#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long typedef vector VI; typedef pair pii; typedef priority_queue PQ; #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i > dp; //vector > > vvvi; //dp=vector >(N, vector(M,0)); //vector > v; //v.push_back(make_pair(x,y)); //priority_queue, greater > q2; vector value; int N; void update(int i, int x) { i += N - 1; value[i] = x; while (i > 0) { i = (i - 1) / 2; value[i] = min(value[i * 2 + 1], value[i * 2 + 2]); } } int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l)return LLINF; if (a <= l && r <= b)return value[k]; else { int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); int c2 = query(a, b, 2 * k + 2, (l + r) / 2,r); return min(c1, c2); } } signed main(){ cin.tie(0); ios::sync_with_stdio(false); int n, q; cin >> n >> q; N = 1; while (N < n)N *= 2; value = vector(2 * N - 1); VI A(n); VI cnt(n + 1); REP(i, value.size())value[i] = LLINF; REP(i, n) { cin >> A[i]; update(i, A[i]); cnt[A[i]] = i; } REP(i, q) { int c; cin >> c; c--; if (!c) { int s,t; cin >> s >> t; swap(cnt[A[s - 1]], cnt[A[t - 1]]); update(s-1, A[t - 1]); update(t-1, A[s - 1]); } else { int s, t; cin >> s >> t; s--; t--; cout << cnt[query(s, t + 1, 0, 0, N)] + 1 << endl; } } return 0; }