#include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; typedef pair P; #define fs first #define sc second P min(P a, P b){ if(a.fs < b.fs){ return a; } else { return b; } } class SegmentTree{ public: int N; vector

node; P INF = P(1LL << 40, 100000000); //コンストラクタ SegmentTree(vector

v){ int sz = v.size(); N = 1; while(N < sz) N *= 2; node.resize(2 * N - 1, INF); for(int i = 0; i < sz; i++){ int k = i + N - 1; node[k] = v[i]; while(k > 0){ k = (k - 1) / 2; node[k] = min(node[k * 2 + 1], node[k * 2 + 2]); } } } //k番目の値(0_indexed)をaに変更 void update(int k, P a){ //葉の節点 k += N - 1; node[k] = a; //登りながら更新 while(k > 0){ k = (k - 1) / 2; node[k] = min(node[k * 2 + 1], node[k * 2 + 2]); } } //[a,b)の最小値 P query(int a, int b){ return Query(a, b, 0, 0, N); } P Query(int a, int b, int k, int l, int r){ if(r <= a || b <= l) return INF; if(a <= l && r <= b) return node[k]; else{ P v1 = Query(a, b, k * 2 + 1, l, (l + r) / 2); P v2 = Query(a, b, k * 2 + 2, (l + r) / 2, r); return min(v1, v2); } } void print(){ for(int i = 0; i < 2 * N - 1; i++){ //cout << "node[" << i << "] " << node[i] << endl; } } }; int main(){ int N, Q; cin >> N >> Q; vector

a(N); for(int i = 0; i < N; i++){ ll tmp; cin >> tmp; a[i] = P(tmp, i); } SegmentTree sg = SegmentTree(a); vector ans; for(int i = 0; i < Q; i++){ int q, l, r; cin >> q >> l >> r; l--; r--; if(q == 1){ P L = sg.query(l, l + 1); P R = sg.query(r, r + 1); sg.update(l, P(R.fs, L.sc)); sg.update(r, P(L.fs, R.sc)); } else { //cout << (sg.query(l, r + 1)).sc << endl; ans.push_back((sg.query(l, r + 1)).sc + 1); } } for(int i : ans){ cout << i << endl; } return 0; }