#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair P; typedef pair Pid; typedef pair Pdi; typedef pair Pl; typedef pair Pll; typedef pair> PP; typedef pair PPi; constexpr double PI = 3.1415926535897932; // acos(-1) constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define chadd(x, y) x = (x + y) % mod template struct SegmentTree{ using F = function; int sz; vector seg; const F f; // モノイドに対して二項演算を行う関数オブジェクト const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){ sz = 1; while(sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x){ seg[k + sz] = x; } void build(){ for(int k = sz - 1; k > 0; --k){ seg[k] = f(seg[k << 1], seg[k << 1 | 1]); } } void update(int k, const Monoid &x){ k += sz; seg[k] = x; while(k >>= 1){ seg[k] = f(seg[k << 1], seg[k << 1 | 1]); } } Monoid query(int a, int b){ Monoid L = M1, R = M1; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){ if(a & 1) L = f(L, seg[a++]); if(b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const{ return seg[k + sz]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; SegmentTree

seg(n, [](P a, P b){return min(a, b);}, P(INF, -1)); for(int i = 0; i < n; ++i){ int a; cin >> a; seg.set(i, P(a, i)); } seg.build(); for(int i = 0; i < q; ++i){ int query, l, r; cin >> query >> l >> r; if(query == 1){ int foo = seg[--l].first, bar = seg[--r].second; seg.update(l, P(bar, l)); seg.update(r, P(foo, r)); } else{ cout << seg.query(--l, r).second + 1 << endl; } } }