#include #include #include using namespace std; struct vindex { int value; int index; }; class segtree { public: int n;//2べき vector data; void init() { data = vector(n * 2); for (int i = 0; i < n * 2; i++) data[i] = {INT_MAX, -1}; } vindex get(int i) { return data[i + n]; } void update(int i, int x) { i += n; data[i] = {x, i - n}; while (i > 0) { i = i / 2; vindex lchild = data[i * 2]; vindex rchild = data[i * 2 + 1]; data[i] = lchild.value < rchild.value ? lchild : rchild; } } vindex query(int a, int b, int k, int l, int r) { if (r <= a || b <= l)return {INT_MAX, -1}; if (a <= l && r <= b)return data[k]; else { vindex lchild = query(a, b, k * 2, l, (l + r) / 2); vindex rchild = query(a, b, k * 2 + 1, (l + r) / 2, r); return lchild.value < rchild.value ? lchild : rchild; } } }; int main() { int n, q; cin >> n >> q; int bin_n = 1; while (bin_n < n)bin_n <<= 1; segtree segtree; segtree.n = bin_n; segtree.init(); for (int i = 0; i < n; i++) { int a; cin >> a; segtree.update(i, a); } for (int i = 0; i < q; i++) { int ope, l, r; cin >> ope >> l >> r; l--; r--; if (ope == 1) { vindex tmpl = segtree.get(l); vindex tmpr = segtree.get(r); segtree.update(l, tmpr.value); segtree.update(r, tmpl.value); } else { cout << segtree.query(l, r + 1, 0, 0, bin_n * 2).index + 1 << endl; } } return 0; }