#include #include #include #include #include #include #include using namespace std; using ll = long long; struct SegmentTree { struct Node { Node(pair p) : v(p) {} Node operator*(const Node &o) const { return { min(v, o.v) }; } pair v; }; SegmentTree(int n) : e({ 1 << 30, -1 }), n(n) { for (m = 2; m < n; m *= 2); t = vector(m + n + n % 2, e); } Node &operator[](int i) { return t[m + i]; } const Node &root() const { return t[1]; } void build() { for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1]; } void update(int i, const Node &o) { for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1]; } Node query(int l, int r) { Node o[2] = { e, e }; for (l += m, r += m; l < r; l /= 2, r /= 2) { if (r & 1) o[1] = t[--r] * o[1]; if (l & 1) o[0] = o[0] * t[l++]; } return o[0] * o[1]; } void print() { for (int j = 1; j <= m; j *= 2) { int k = min(j * 2, m + n); for (int i = j; i < k; i++) { cout << t[i].v.first << " \n"[i == k - 1]; } } } vector t; const Node e; int n, m; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; SegmentTree st(n); for (int i = 0; i < n; i++) { int a; cin >> a; st[i] = SegmentTree::Node({ a, i }); } st.build(); for (int h = 0; h < q; h++) { int t, l, r; cin >> t >> l >> r; if (t == 1) { l--; r--; auto ln = st[l]; auto rn = st[r]; swap(ln.v.first, rn.v.first); st.update(l, ln); st.update(r, rn); } else { l--; auto qn = st.query(l, r); cout << qn.v.second + 1 << '\n'; } } return 0; }