#include #define int long long #define mod (int)(1e9+7) #define inf (int)(3e18) #define rep(i,n) for(int i=0;i #define PiP pair> #define PP pair #define all(v) v.begin(),v.end() #define mkp make_pair #define mkt make_tuple #define prique(T) priority_queue,greater> #define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end()) using namespace std; template inline void chmax(T& a, T b) { a = max(a, b); } template inline void chmin(T& a, T b) { a = min(a, b); } bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return x != 1; } int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x)return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int get_rand(int MIN, int MAX) { random_device rnd; mt19937_64 mt64(rnd()); uniform_int_distributionengine(MIN, MAX); return engine(mt64); } /*--------Library Zone!--------*/ struct Segtree { int size = 1; vectordat, index; Segtree(int x) { while (size < x)size *= 2; index.resize(2 * size - 1); dat.resize(2 * size - 1); rep(i, 2 * size - 1) { dat[i] = inf; index[i] = i; } } void update(int a, int b, int k = 0, int l = 0, int r = -1) { if (r == -1)r = size; if (r - l == 1) { dat[k] = b; index[k] = l; return; } if (a < (l + r) / 2) { update(a, b, k * 2 + 1, l, (l + r) / 2); } else { update(a, b, k * 2 + 2, (l + r) / 2, r); } if (dat[k * 2 + 1] < dat[k * 2 + 2]) { dat[k] = dat[k * 2 + 1]; index[k] = index[k * 2 + 1]; } else { dat[k] = dat[k * 2 + 2]; index[k] = index[k * 2 + 2]; } } P query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r == -1)r = size; if (r <= a || b <= l)return { inf,-1 }; if (a <= l && r <= b) { return { dat[k],index[k] }; } P lval = query(a, b, k * 2 + 1, l, (l + r) / 2); P rval = query(a, b, k * 2 + 2, (l + r) / 2, r); if (lval.first < rval.first) { return { lval.first,lval.second }; } else { return { rval.first,rval.second }; } } }; int n, q; signed main() { cin >> n >> q; Segtree segtree(n); rep(i, n) { int a; cin >> a; segtree.update(i, a); } rep(i, q) { int a, b, c; cin >> a >> b >> c; b--; c--; if (a == 1) { int lval = segtree.query(b, b + 1).first; int rval = segtree.query(c, c + 1).first; segtree.update(b, rval); segtree.update(c, lval); } else { int d = segtree.query(b, c + 1).second; cout << max(d - b, c - d) + 1 << endl; } } }