#include using namespace std; #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif #define int long long const int INF = 1LL << 60; template struct SegmentTree{ using F = function; F f; T inf; int n; vector node; SegmentTree(){} SegmentTree(vector v,T inf,F f):inf(inf),f(f){ n = 1; while(n < v.size()) n *= 2; node.resize(2*n-1,inf); for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i]; for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]); } void update(int k,T val){ k += n-1; node[k] = val; while(k > 0){ k = (k-1) / 2; node[k] = f(node[2*k+1],node[2*k+2]); } } void add(int k,T val){ k += n-1; node[k] += val; while(k > 0){ k = (k-1) / 2; node[k] = f(node[2*k+1],node[2*k+2]); } } T getval(int a,int b){ return getval(a,b,0,0,n); } T getval(int a,int b,int k,int l,int r){ //区間[a, b)の値を返す if(r <= a || b <= l) return inf; if(a <= l && r <= b) return node[k]; T vl = getval(a, b, 2*k+1, l, (l+r)/2); T vr = getval(a, b, 2*k+2, (l+r)/2, r); return f(vl, vr); } void print(){ for(int i = 0; i < n; i++){ cout << node[i+n-1] << " "; } cout << endl; } }; using P = pair; signed main(){ int n, q; cin >> n >> q; vector

a(n); for(int i = 0; i < n; i++){ cin >> a[i].first; a[i].second = i+1; } SegmentTree

seg(a,P(INF, INF),[&](P x, P y){ return min(x, y); }); for(int i = 0; i < q; i++){ int c, l, r; cin >> c >> l >> r; l--, r--; if(c == 1){ P p = seg.getval(l, l+1), q = seg.getval(r, r+1); swap(p.second, q.second); seg.update(l, q); seg.update(r, p); }else{ cout << seg.getval(l, r+1).second << endl; } } return 0; }