#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 - 1); for (int i = 0; i < n * 2 - 1; i++) data[i] = {INT_MAX, -1}; } void update(int i, int x) { i += n - 1; data[i] = {x, i - (n - 1)}; while (i > 0) { i = (i - 1) / 2; vindex lchild = data[i * 2 + 1]; vindex rchild = data[i * 2 + 2]; 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 + 1, l, (l + r) / 2); vindex rchild = query(a, b, k * 2 + 2, (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.data[l]; vindex tmpr = segtree.data[r]; segtree.update(l, tmpr.value); segtree.update(r, tmpl.value); } else { cout << segtree.query(l, r + 1, 0, 0, bin_n).index + 1 << endl; } } return 0; }