//include //------------------------------------------ #include #include #include #include #include #include #include #include #include #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; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; //------------------------------------------ //------------------------------------------ template struct SegmentTree { private: using Func = function; int n; vector node; T init_v; Func func; public: SegmentTree(vector a, Func _func, T _init_v) { int sz = a.size(); n = 1; init_v = _init_v; func = _func; while (n < sz) n *= 2; node.resize(2 * n, init_v); for (int i = 0; i < sz; i++) node[i + n - 1] = a[i]; for (int i = n - 2; i >= 0; i--) node[i] = func(node[i * 2 + 1], node[i * 2 + 2]); } void update(int pos, T v) { int k = pos + n - 1; node[k] = v; while (k > 0) { k = (k - 1) / 2; node[k] = func(node[k * 2 + 1], node[k * 2 + 2]); } } T get(int pos) { int k = pos + n - 1; return node[k]; } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return init_v; if (a <= l && r <= b)return node[k]; T lv = query(a, b, k * 2 + 1, l, (l + r) / 2); T rv = query(a, b, k * 2 + 2, (l + r) / 2, r); return func(lv, rv); } }; int main() { int N; cin >> N; int Q; cin >> Q; vector a(N); for (int i = 0; i < N; i++) cin >> a[i]; SegmentTree tree(a, [](const int a, const int b) { return min(a, b); }, INT_MAX); map mp; for (int i = 0; i < N; i++) mp[a[i]] = i; for (int i = 0; i < Q; i++) { int which, l, r; cin >> which >> l >> r; l--, r--; if (which == 1) { int lv = tree.get(l); int rv = tree.get(r); tree.update(r, lv); tree.update(l, rv); mp[lv] = r; mp[rv] = l; } if (which == 2) { cout << mp[tree.query(l, r + 1)] + 1 << endl; } } }