#include using namespace std; using ll = long long; using PII = std::pair; using PLL = std::pair; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) class RangeMinorMaxorSumQuery // 0-index { int const intmax = 2147483647; int const intmin = 0; vector sgt; int n; int k; public: RangeMinorMaxorSumQuery(int n1, int f = -1) { if (f == -1) f = intmax; else if (f == 0) f = intmin; int na = 1; int ka = 0; while (na < n1) { na *= 2; ka++; } for (int i = 0; i < 2 * na; i++) sgt.push_back(make_pair(f, i)); n = na; k = ka; } void update_min(int i, int x) { i += n; sgt[i] = make_pair(x, i - n + 1); while (i > 1) { i /= 2; sgt[i] = min(sgt[2 * i], sgt[2 * i + 1]); } } PII getmin(int a, int b, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする { if (r == -1) r = n; if (r <= a || b <= l) return make_pair(intmax, -1); if (a == l && b == r) return sgt[k]; else return min(getmin(a, min(b, (l + r) / 2), 2 * k, l, (l + r) / 2), getmin(max(a, (l + r) / 2), b, 2 * k + 1, (l + r) / 2, r)); } void printsegtree() { for (int i = 0; i < 2 * n; i++) { cout << "(" << sgt[i].first << " " << sgt[i].second << ")" << " "; } cout << endl; } }; int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif int n, q, w, op, l, r, ln, rn; cin >> n >> q; RangeMinorMaxorSumQuery rmq(n); rep(i, n) { cin >> w; rmq.update_min(i, w); } rep(i, q) { cin >> op >> l >> r; if (op == 1) { ln = rmq.getmin(l-1, l).first; rn = rmq.getmin(r-1, r).first; rmq.update_min(l-1, rn); rmq.update_min(r-1, ln); // rmq.update_min(l, w); // rmq.update_min(l, w); } else { cout << rmq.getmin(l-1, r).second << endl; } } return 0; }