#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for(int (i) = 0; (i) < (n); ++(i)) #define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i)) #define ALL(TheArray) TheArray.begin(), TheArray.end() using lli = long long int; using pii = std::pair; template inline bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template inline bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class SegTree{ #define rep(i, n) for(int (i) = 0; (i) < (n); ++(i)) const int N; const int n; const std::function F; const T identityValue; std::vector theTree; int computeLength(int m){ int res = 1; while(res < m) res <<= 1; return res; } T preGetValue(int a, int b, int k, int l, int r){ if(r <= a or b <= l) return identityValue; if(a <= l and r <= b) return theTree[k]; T vl = preGetValue(a, b, 2*k+1, l, (l+r)/2); T vr = preGetValue(a, b, 2*k+2, (l+r)/2, r); return F(vl, vr); } public: SegTree(std::vector& V, std::function f1, T idV) :n(V.size()), N(computeLength(V.size())), F(f1), identityValue(idV) { theTree.resize(2 * N - 1); int i; for(i = 0; i < n; ++i) theTree[i + N - 1] = V[i]; for(i = n; i < N; ++i) theTree[i + N - 1] = identityValue; for(i = N - 2;i >= 0; --i) theTree[i] = F(theTree[2*i+1], theTree[2*i+2]); } bool update(int x, T val){ if(x < 0 or x >= n) return false; int y = x + N - 1; theTree[y] = val; while(y > 0){ (--y) >>= 1; theTree[y] = F(theTree[2*y+1], theTree[2*y+2]); } return true; } T at(int idx){return theTree[idx + N - 1];} T getValue(int a, int b){ return preGetValue(a, b, 0, 0, N); } #undef rep }; constexpr int inf = 2e9; constexpr pii infP = {inf, inf}; const std::function minfunc = [](pii x, pii y){return x > y ? y : x;}; std::vector A; int main(void){ int n, Q; scanf("%d%d", &n, &Q); A.resize(n); REP(i, n) {scanf("%d", &A[i].first); A[i].second = i;} SegTree ST(A, minfunc, infP); while(Q--){ int q, l, r; scanf("%d%d%d", &q, &l, &r); l--; r--; if(q == 1){ pii vL = ST.at(l); pii vR = ST.at(r); ST.update(l, {vR.first, l}); ST.update(r, {vL.first, r}); } else{ printf("%d\n", ST.getValue(l, r+1).second + 1); } } return 0; }