#include using namespace std; struct SegmentTree { const int INF = numeric_limits::max(); int n; vector node; vector> pnode; SegmentTree(vector v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, INF); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; 0 <= i; i--) { node[i] = min(node[i * 2 + 1], node[i * 2 + 2]); } } SegmentTree(vector> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; pnode.resize(2 * n - 1); for (int i = 0; i < 2 * n - 1; i++) pnode[i] = make_pair(INF, -1); for (int i = 0; i < sz; i++) pnode[i + n - 1] = make_pair(v[i].first, i + 1); for (int i = n - 2; 0 <= i; i--) { if (pnode[i * 2 + 1].first < pnode[i * 2 + 2].first) { pnode[i] = pnode[i * 2 + 1]; } else { pnode[i] = pnode[i * 2 + 2]; } } } SegmentTree(vector v, int x) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, x); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; 0 <= i; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } // x番目の要素をvalに更新する void update(int x, int val) { x += (n - 1); node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } void update2(int x, pair val) { x += (n - 1); pnode[x].first = val.first; while (x > 0) { x = (x - 1) / 2; if (pnode[x * 2 + 1].first < pnode[x * 2 + 2].first) { pnode[x] = pnode[x * 2 + 1]; } else { pnode[x] = pnode[x * 2 + 2]; } } } // 区間[a, b)の要素の最小値を返す. k := 自分がいるノードのインデックス int getmin(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return INF; if (a <= l && r <= b) return node[k]; int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2); int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } pair getmin2(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return make_pair(INF, -1); if (a <= l && r <= b) return pnode[k]; pair vl = getmin2(a, b, 2 * k + 1, l, (l + r) / 2); pair vr = getmin2(a, b, 2 * k + 2, (l + r) / 2, r); return (vl.first < vr.first ? vl : vr); } void add(int k, int val) { k += (n - 1); node[k] += val; while (k > 0) { k = (k - 1) / 2; node[k] = node[2 * k + 1] + node[2 * k + 2]; } } int getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; int vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); int vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; int main() { int N, Q; cin >> N >> Q; vector> a(N); for (int i = 0; i < N; i++) { cin >> a[i].first; a[i].second = i + 1; } SegmentTree seg(a); int com, l, r; for (int i = 0; i < Q; i++) { cin >> com >> l >> r; l--, r--; if (com == 1) { pair al = seg.pnode[l + N]; pair ar = seg.pnode[r + N]; seg.update2(l, ar); seg.update2(r, al); } else { cout << seg.getmin2(l, r + 1).second << endl; } } return 0; }