#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } using ll = long long; using pii = pair; using pll = pair; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; /*RMAXQ by SegmentTree */ struct SegmentTree { int n; vector dat; SegmentTree(int _n) { n = 1; while(n < _n) n *= 2; dat.resize(2 * n - 1); for(int i = 0; i < 2 * n - 1; i++) dat[i] = INF; } SegmentTree(vector v) { int sz = v.size(); n = 1; while(n < sz) n *= 2; dat.resize(2 * n - 1); for(int i = 0; i < sz; i++) dat[i + n - 1] = v[i]; for(int i = n - 2; i >= 0; i--) { dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]); } } void update(int k, int a) { k += n - 1; dat[k] = a; while(k > 0) { k = (k - 1) / 2; dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); } } int _query(int a, int b, int k, int l, int r) { if(r <= a || b <= l) return INF; //交差しない if(a <= l && r <= b) return dat[k]; //完全に含んでいる else { int vl = _query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = _query(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr); } } int query(int i, int j) { return _query(i, j, 0, 0, n); } }; int main() { int N, Q; cin >> N >> Q; vector A(N); rep(i, N) cin >> A[i]; rep(i, N) A[i]--; SegmentTree segtree(A); vector indices(N); rep(i, N) { indices[A[i]] = i; } rep(i, Q) { int q, l, r; cin >> q >> l >> r; l--, r--; if(q == 1) { int tmp1 = segtree.query(l, l + 1), tmp2 = segtree.query(r, r + 1); segtree.update(l, tmp2); segtree.update(r, tmp1); indices[tmp1] = r; indices[tmp2] = l; } else { int mi = segtree.query(l, r + 1); cout << indices[mi] + 1 << endl; } } return 0; }