import sequtils,strutils,algorithm type binaryIndexTree[I:static[int]] = array[I + 1,int64] item = tuple[p,t,i : int64] qs = tuple[l,r,x : int64] 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 var N, Q : int64 (N, Q) = stdin.readline.split.map(parseBiggestInt) var BITa = initBit(100010) BITf = initBit(100010) A : seq[int64] = @[0.int64] & stdin.readline.split.map(parseBiggestInt) S : array[100010, int64] items = newSeq[item](0) ans : array[100010, int64] l0, l, r, x : int64 Qs : array[100010,qs] for i, a in A: if i == 0: continue BITa.add(i, a) BITf.add(i, 1) items.add((a, 0.int64, i.int64)) for q in 0..