import sequtils,strutils,algorithm type binaryIndexTree[I:static[int]] = array[I + 1,int64] item = tuple[p,t,i : int64] qs = tuple[l,r : int64] segmenttree[I : static[int]] = array[2 shl I,int] # segT[0] にはnを入れる,要素数 <= 1 shl n proc update(ST : var segmenttree, index : int, n : int)= var j = index + (1 shl ST[0]) flag = true ST[j] = n while flag and j > 1: if ST[j shr 1] != max(ST[j], ST[j xor 1]): ST[j shr 1] = max(ST[j], ST[j xor 1]) j = j shr 1 else: flag = false proc Rmax(ST : segmenttree; l : int ;r : int; a = 1 ; cnt = 0):int= if a shl (ST[0] - cnt) - (1 shl ST[0]) == l and ((a + 1) shl (ST[0] - cnt)) - 1 - (1 shl ST[0]) == r: return ST[a] else: var n : int n = (a shl 1) + 1 n = n shl (ST[0] - cnt - 1) if n - (1 shl ST[0]) <= l: return Rmax(ST, l, r, (a shl 1) + 1, cnt + 1) elif n - (1 shl ST[0]) > r: return Rmax(ST, l, r, a shl 1, cnt + 1) else: return max(Rmax(ST, l, n - 1 - (1 shl ST[0]), a shl 1, cnt + 1), Rmax(ST, n - (1 shl ST[0]), r, (a shl 1) + 1, cnt + 1)) proc add(BIT :var binaryIndexTree,i : int64, a : int64)= var index = i while BIT[0] >= index: BIT[index] += a index += ((index xor (index - 1)) and index) proc sum(BIT : binaryIndexTree, i : int64):int64 = var index = i while index > 0: result += BIT[index] index = (index and (index - 1)) proc initBit(i : static[int]) : binaryIndexTree[i] = var res : binaryIndexTree[i] res[0] = i return res proc initsegtree(i : static[int]) : segmenttree[i] = var res : segmenttree[i] res[0] = i return res var N, Q : int64 (N, Q) = stdin.readline.split.map(parseBiggestInt) var BIT = initBit(100010) st : segmenttree[18] A : seq[int64] = @[0.int64] & stdin.readline.split.map(parseBiggestInt) n : array[100010, int64] items = newSeq[item](0) ans : array[100010, int64] l0, l, r : int64 Qs : array[100010,qs] st[0] = 18 for i, a in A: if i == 0: continue n[i] = st.Rmax(a.int + 1, 100007) st.update(a.int, i) BIT.add(i, 1) items.add((n[i], 0.int64, i.int64)) for q in 0..