#include #include #include #include using namespace std; template struct SegmentTree { using F = function; const F f; const Monoid M1; int sz; vector dat; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) { while (sz < n) sz <<= 1; dat.assign(sz * 2, M1); } void set(int k, const Monoid &x) { dat[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { dat[k] = f(dat[2 * k], dat[2 * k + 1]); } } void update(int k, const Monoid &x) { dat[k += sz] = x; while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]); } Monoid get(int a, int b) { // [a, b) Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, dat[a++]); if (b & 1) R = f(dat[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return dat[k + sz]; } friend ostream& operator<<(ostream& os, SegmentTree &seg) { for (int i = 0; i < seg.sz; i++) os << seg[i] << " "; return os; } }; const int INF = numeric_limits::max(); int main() { int n, q; cin >> n >> q; using P = pair; SegmentTree

seg(n + 1, [](P a, P b) { return min(a, b); }, {INF, 0}); for (int i = 1; i <= n; i++) { int a; cin >> a; seg.set(i, P(a, i)); } seg.build(); while (q--) { int com, l, r; cin >> com >> l >> r; if (com == 1) { int al = seg[l].first, ar = seg[r].first; seg.update(l, P(ar, l)); seg.update(r, P(al, r)); } else { cout << seg.get(l, r + 1).second << endl; } } return 0; }