import sequtils,strutils type item = tuple[a, i : int] segmenttree[I:static[int]] = array[2 shl I,item] # segT[0] にはnを入れる,要素数 <= 1 shl n proc update(ST : var segmenttree, index : int, n : item)= var j = index + (1 shl ST[0].a) flag = true ST[j] = n while flag and j > 1: if ST[j shr 1] != min(ST[j], ST[j xor 1]): ST[j shr 1] = min(ST[j], ST[j xor 1]) j = j shr 1 else: flag = false proc Rmin(ST : segmenttree; l : int ;r : int; a = 1 ; cnt = 0):item= if a shl (ST[0].a - cnt) - (1 shl ST[0].a) == l and ((a + 1) shl (ST[0].a - cnt)) - 1 - (1 shl ST[0].a) == r: return ST[a] else: var n : int n = (a shl 1) + 1 n = n shl (ST[0].a - cnt - 1) if n - (1 shl ST[0].a) <= l: return Rmin(ST, l, r, (a shl 1) + 1, cnt + 1) elif n - (1 shl ST[0].a) > r: return Rmin(ST, l, r, a shl 1, cnt + 1) else: return min(Rmin(ST, l, n - 1 - (1 shl ST[0].a), a shl 1, cnt + 1), Rmin(ST, n - (1 shl ST[0].a), r, (a shl 1) + 1, cnt + 1)) var N, Q : int (N, Q) = stdin.readline.split.map(parseInt) var A = stdin.readline.split.map(parseInt) st : segmenttree[18] st[0].a = 18 for i,a in A: st.update(i + 1, (a, i + 1)) for i in 1..Q: var line = stdin.readline.split.map(parseInt) var l = line[1] var r = line[2] if line[0] == 1: (A[l - 1], A[r - 1]) = (A[r - 1], A[l - 1]) st.update(l, (A[l - 1], l)) st.update(r, (A[r - 1], r)) else: echo st.Rmin(line[1], line[2]).i