#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define REPR(i, n) for(ll i = n;i >= 0;i--) #define FOR(i, m, n) for(ll i = m;i < n;i++) #define FORR(i, m, n) for(ll i = m;i >= n;i--) #define REPO(i, n) for(ll i = 1;i <= n;i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(),n.end() #define MOD (ll)1000000007 #define P pair //セグ木 ll dat[510000], sz; void init(ll n) { sz = 1; while (sz < n)sz *= 2; REP(i, sz) { dat[i] = INF; } } void update(ll k, ll a) { //場所(0-indexed), 値 k += sz - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); //更新 } } ll query(ll a, ll b, ll k, ll l, ll r) { //[a, b) 呼ぶとき (a, b, 0, 0, sz) if (r <= a or b <= l)return INF; if (a <= l and r <= b)return dat[k]; ll v1 = query(a, b, k * 2 + 1, l, (l + r) / 2); ll v2 = query(a, b, k * 2 + 2, (l + r) / 2, r); return min(v1, v2); //戻り値 } ll n, q, num[110000]; int main() { cin >> n >> q; init(n); REP(i, n) { ll a; cin >> a; a--; update(i, a); num[a] = i; } REP(i, q) { ll s, l, r; cin >> s >> l >> r; l--; r--; if (s == 1) { ll a = dat[l + sz - 1], b = dat[r + sz - 1]; update(l, b); update(r, a); num[a] = r; num[b] = l; } else { ll a = query(l, r + 1, 0, 0, sz); cout << num[a] + 1 << endl; } } }