#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) int const INF = INT_MAX; struct SegmentTree { private: int n; vector

node; public: SegmentTree(vector

v) { int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2*n-1,P(INF,-1)); for (int i = 0;i < sz;++i) node[i+n-1] = v[i]; for (int i = n-2;i >= 0;--i) node[i] = min(node[2*i+1],node[2*i+2]); } void update(int x,P val) { x += (n-1); node[x] = val; while (x > 0) { x = (x-1)/2; node[x] = min(node[2*x+1],node[2*x+2]); } } P getmin(int a,int b,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return P(INF,-1); if (a <= l && r <= b) return node[k]; P vl = getmin(a,b,2*k+1,l,(l+r)/2); P vr = getmin(a,b,2*k+2,(l+r)/2,r); return min(vl,vr); } }; int main() { int n,q; cin >> n >> q; vector

a(n); vector b(n); for (int i = 0;i < n;++i) { cin >> a[i].first; a[i].second = i; b[i] = i+1; } SegmentTree seg(a); for (int z = 0;z < q;++z) { int c,l,r; cin >> c >> l >> r; if (c == 1) { P v = seg.getmin(l-1,l); seg.update(l-1,seg.getmin(r-1,r)); seg.update(r-1,v); swap(b[l-1],b[r-1]); } else cout << b[seg.getmin(l-1,r).second] << endl; } }