#include using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) int const inf = INT_MAX; struct SegmentTree { private: int n; vector> node; public: SegmentTree(vector> v) { int sz = v.size(); n = 1; // 2の累乗の大きさにする while (n < sz) n *= 2; // 余りをinfで埋める //node.resize(2*n-1, inf); node.resize(2*n-1); rep(i, 2*n-1) { node[i].first = inf; node[i].second = n; } // 葉を構築 for (int i = 0; i < sz; i++) { node[i+n-1].first = v[i].first; node[i+n-1].second = v[i].second; } // 親を構築 for (int i = n - 2; i >= 0; i--) { if (node[2*i+1].first < node[2*i+2].first) { node[i].first = node[2*i+1].first; node[i].second = node[2*i+1].second; } else { node[i].first = node[2*i+2].first; node[i].second = node[2*i+2].second; } //node[i].first = min(node[2*i+1].first, node[2*i+2].first); } } void update(int x, int val, int ind) { x += (n - 1); node[x].first = val; node[x].second = ind; while (x > 0) { x = (x - 1) / 2; if (node[2*x+1].first < node[2*x+2].first) { node[x].first = node[2*x+1].first; node[x].second = node[2*x+1].second; } else { node[x].first = node[2*x+2].first; node[x].second = node[2*x+2].second; } //node[x].first = min(node[2*x+1].first, node[2*x+2].first); } } pair getmin(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) { pair c = make_pair(inf, n); return c; } if (a <= l && r <= b) return node[k]; pair vl = getmin(a, b, 2*k+1, l, (l+r) / 2); pair vr = getmin(a, b, 2*k+2, (l+r) / 2, r); if (vl.first > vr.first) { return vr; } else { return vl; } } }; int main() { int N, Q; cin >> N >> Q; vector> a(N); rep(i, N) { int x; cin >> x; a[i] = make_pair(x, i+1); } SegmentTree seg(a); rep(_, Q) { int k, l, r; cin >> k >> l >> r; if (k == 1) { seg.update(l-1, a[r-1].first, l); seg.update(r-1, a[l-1].first, r); } else { pair z = seg.getmin(l, r+1); cout << z.second << endl; } } return 0; }