#include #include #include using namespace std; struct vindex { int value; int index; }; int n=1;//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 wantl, int wantr, int k, int nowl, int nowr) { if (nowr < wantl || wantr <= nowl)return {INT_MAX, -1}; if (wantl <= nowl && nowr <= wantr)return data[k]; else { vindex lchild = query(wantl, wantr, k * 2 + 1, nowl, (nowl + nowr) / 2); vindex rchild = query(wantl, wantr, k * 2 + 2, (nowl + nowr) / 2, nowr); return lchild.value < rchild.value ? lchild : rchild; } } int main() { int arrsize, q; cin >> arrsize >> q; while (n < arrsize)n <<= 1; init(); for (int i = 0; i < n; i++) { int a; cin >> a; 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 = data[l]; vindex tmpr = data[r]; update(l, tmpr.value); update(r, tmpl.value); } else { cout << query(l, r + 1, 0, 0, n).index + 1 << endl; } } return 0; }