#include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) using namespace std; typedef long long int ll; typedef pair pii; typedef pair pll; template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } template typename enable_if::value == 0>::type fill_v(T& t, const V& v) { t = v; } template typename enable_if::value != 0>::type fill_v(T& t, const V& v) { for (auto& e : t) fill_v(e, v); } #define ARRAY_MAX 100005 const int INF = 1e9; const ll MOD = 1e9 + 7; int dx[4] = { 1,0,0,-1 }; int dy[4] = { 0,1,-1,0 }; /******************************************************************************************/ //RMQ //セグ木 struct SegmentTree { private: int N; vector node;//0-index public: SegmentTree(int siz) { N = 1; while (N < siz) { N *= 2; } node.resize(2 * N - 1, pii(INF,0)); } void build(vector& dat) { for (int i = 0; i < dat.size(); i++) { node[i + N - 1] = dat[i]; } for (int i = N - 2; i >= 0; i--) { if (node[2 * i + 1].first >= node[2 * i + 2].first) { node[i] = node[2 * i + 2]; } else { node[i] = node[2 * i + 1]; } } } void update(int k, int x) { k += N - 1; node[k].first = x; while (k > 0) { k = (k - 1) / 2;//親 if (node[2 * k + 1].first >= node[2 * k + 2].first) { node[k] = node[2 * k + 2]; } else { node[k] = node[2 * k + 1]; } } } //[a,b) pii getMin(int a, int b) { return getMin(a, b, 0, 0, N); } pii getMin(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return pii(INF,-1); } if (a <= l && r <= b) { return node[k]; } pii vl = getMin(a, b, k * 2 + 1, l, (l + r) / 2); pii vr = getMin(a, b, k * 2 + 2, (l + r) / 2, r); if (vl.first >= vr.first) { return vr; } else { return vl; } } }; int 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; } SegmentTree segtree(n); segtree.build(a); for (int i = 0; i < q; i++) { int h, l, r; cin >> h >> l >> r; l--; r--; if (h == 1) { //swap pii left = segtree.getMin(l, l + 1); pii right = segtree.getMin(r, r + 1); swap(left.second, right.second); //cout << left.first << " left" << left.second << endl; //cout << right.first << " right " << right.second << endl; segtree.update(l, right.first); segtree.update(r, left.first); } else { //min //cout << segtree.getMin(l, r + 1).first << " ans value = " << segtree.getMin(l, r + 1).second << endl; cout << segtree.getMin(l, r + 1).second+1 << endl; } } return 0; }