#line 2 "library/src/template.hpp" #include #define rep(i, N) for (int i = 0; i < (N); i++) #define all(x) (x).begin(),(x).end() #define popcount(x) __builtin_popcount(x) using i128=__int128_t; using ll = long long; using ld = long double; using graph = std::vector>; using P = std::pair; constexpr int inf = 1e9; constexpr ll infl = 1e18; constexpr ld eps = 1e-6; const long double pi = acos(-1); constexpr uint64_t MOD = 1e9 + 7; constexpr uint64_t MOD2 = 998244353; constexpr int dx[] = { 1,0,-1,0 }; constexpr int dy[] = { 0,1,0,-1 }; templateconstexpr inline void chmax(T&x,T y){if(xconstexpr inline void chmin(T&x,T y){if(x>y)x=y;} #line 3 "library/src/data-structure/segtree.hpp" namespace kyopro { /// @brief Segment Tree template class segtree { int lg, sz, n; std::vector dat; public: segtree() {} segtree(int n) : segtree(std::vector(n, e())) {} segtree(const std::vector& vec) : n((int)vec.size()) { sz = 1, lg = 0; while (sz <= n) { sz <<= 1; lg++; } dat = std::vector(sz << 1, e()); for (int i = 0; i < n; i++) { set(i, vec[i]); } build(); } void set(int p, const S& v) { dat[sz + p] = v; } void build() { for (int i = sz - 1; i > 0; i--) { dat[i] = op(dat[(i << 1) | 0], dat[(i << 1) | 1]); } } S operator[](int p) const { return dat[sz + p]; } void update(int p, const S& v) { p += sz; dat[p] = v; while (p >>= 1) { dat[p] = op(dat[(p << 1) | 0], dat[(p << 1) | 1]); } } S prod(int l, int r) const { if (l == 0 && r == n) { return dat[1]; } l += sz, r += sz; S sml = e(), smr = e(); while (l != r) { if (l & 1) sml = op(sml, dat[l++]); if (r & 1) smr = op(dat[--r], smr); l >>= 1, r >>= 1; } return op(sml, smr); } void apply(int p, const S& v) { update(p, op(dat[sz + p], v)); } }; }; // namespace kyopro /// @docs docs/data-structure/segtree.md #line 3 "main.cpp" using namespace std; constexpr inline P op(P a, P b) { return min(a, b); } constexpr inline P e() { return {inf, inf}; } int main() { int n,q; scanf("%d%d", &n, &q); kyopro::segtree seg(n + 1); for (int i = 1; i <= n; ++i) { int a; scanf("%d",&a); seg.set(i, {a, i}); } seg.build(); while(q--){ int t,l,r; scanf("%d%d%d", &t, &l, &r); if (t == 1) { auto [a, b] = P{seg[l].first, seg[r].first}; swap(a, b); seg.update(l, {a, l}), seg.update(r, {b, r}); } else{ printf("%d\n", seg.prod(l, r + 1).second); } } }