import sequtils # import algorithm,math,tables # import times,macros,queues,bitops,strutils,intsets,sets # import rationals,critbits,ropes,nre,pegs,complex,stats,heapqueue,sugar template times*(n:int,body) = (for _ in 0.." ,discardable.} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord type BinaryIndexedTree[T] = ref object data: seq[T] proc newBinaryIndexedTree[T](n:int):BinaryIndexedTree[T] = new(result) result.data = newSeq[T](n) proc len[T](self:BinaryIndexedTree[T]): int = self.data.len() proc plus[T](self:var BinaryIndexedTree[T],i:int,val:T) = var i = i while i < self.len(): self.data[i] += val i = i or (i + 1) proc `[]`[T](self:BinaryIndexedTree[T],i:int): T = var i = i while i >= 0: result += self.data[i] i = (i and (i + 1)) - 1 proc `$`[T](self:BinaryIndexedTree[T]): string = result = "[" for i in 0.. 100 : " ...]" else: "]") let n = scan() let q = scan() let B = newSeqWith(n,scan()) var A = newBinaryIndexedTree[int](n+10) var D = newBinaryIndexedTree[int](n+10) for i in 1..