import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') type SegTree = object tree :seq[HashSet[int]] n:int proc initSegTree(baseArr:seq[HashSet[int]]):SegTree= var n = baseArr.len var m = 1 while m < n: m*=2 result = SegTree() result.n = m result.tree = newseqwith(2*m-1,initHashSet[int]()) for i, v in baseArr: result.tree[m-1+i]=v for idx in countdown(m-2,0): result.tree[idx] = result.tree[idx*2+1]+result.tree[idx*2+2] proc get(segTree:SegTree,ql,qr:int,k:int=0,left:int=0,right:int= -1):HashSet[int]= var right=right if right<0: right = segTree.n #echo ql,", ", qr, ", ",left,", ", right if ql>=right or qr<=left: return initHashSet[int]() if ql <= left and right <= qr: return segTree.tree[k] var vl = segTree.get(ql,qr,2*k+1,left,(left+right).div(2)) vr = segTree.get(ql,qr,2*k+2,(left+right).div(2),right) return vl+vr proc set(segTree:var SegTree,idx:int,value:HashSet[int])= var k = segTree.n - 1 + idx segTree.tree[k] = value while k>=1: k = (k-1).div(2) if segTree.tree[k] == segTree.tree[2*k+1]+segTree.tree[2*k+2]: break else: segTree.tree[k] = segTree.tree[2*k+1]+segTree.tree[2*k+2] var baseArr = newseqwith(50,initHashSet[int]()) for i in 0..<10: baseArr[i] = @[i].toHashSet var segTree = baseArr.initSegTree() #echo segTree.tree segTree.set(0,@[5].toHashSet()) #echo segTree.tree proc solveSegTree()= var n = scan() m = scan() r = newseqwith(n,newseqwith(m,scan())) maxParam = newseqwith(m,0) maxParamPlayer = newseqwith(m,initHashSet[int]()) segTree = maxParamPlayer.initSegTree() for k in 0..