import sequtils import times template stopwatch(body) = (let t1 = cpuTime();body;echo "TIME:",(cpuTime() - t1) * 1000,"ms") template stopwatch(body) = body proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int32 = while true: let k = getchar_unlocked() if k < '0': return result = 10.int32 * result + k.ord.int32 - '0'.ord.int32 type BinaryIndexedTree*[CNT:static[int],T] = object data: array[CNT,T] # 引数以下の部分和(Fenwick Tree) proc len*[CNT,T](bit:BinaryIndexedTree[CNT,T]): int = bit.data.len() proc update*[CNT,T](bit:var BinaryIndexedTree[CNT,T],i:int,val:T) = var i = i while i < bit.len(): bit.data[i] += val i = i or (i + 1) proc `[]`*[CNT,T](bit:BinaryIndexedTree[CNT,T],i:int): T = var i = i while i >= 0: result += bit.data[i] i = (i and (i + 1)) - 1 proc `$`*[CNT,T](bit:BinaryIndexedTree[CNT,T]): string = result = "[" for i in 0.. 100 : " ...]" else: "]") let n = scan() var E : array[200010,seq[int32]] var bit : BinaryIndexedTree[200010,int32] stopwatch: for i in 1.int32..