import heapq class Heap_Dict: def __init__(self,Mode=True): """ Mode:True→最小値,False→最大値 """ self.heap=[] self.dict={} self.Mode=Mode def __bool__(self): return bool(self.heap) def insert(self,x): if self.Mode and not self.is_exist(x): heapq.heappush(self.heap,x) elif not self.Mode and not self.is_exist(x): heapq.heappush(self.heap,-x) if x in self.dict: self.dict[x]+=1 else: self.dict[x]=1 def erase(self,x): assert (x in self.dict) and (self.dict[x]) self.dict[x]-=1 while self.heap: y=self.heap[0] if not self.Mode:y=-y if self.dict[y]==0: heapq.heappop(self.heap) else: break def is_exist(self,x): return (x in self.dict) and (self.dict[x]) def get_min(self): assert self.Mode if self.heap: return self.heap[0] else: return float("inf") def get_max(self): assert not self.Mode if self.heap: return -self.heap[0] else: return -float("inf") def count(self,x): if x not in self.dict: return 0 else: return self.dict[x] class Segment_Tree(): """ このプログラム内は1-index """ def __init__(self,L,calc,unit,index): """calcを演算とするリストLのSegment Treeを作成 calc:演算(2変数関数,モノイド) unit:モノイドcalcの単位元 (xe=ex=xを満たすe) index:数列の第1要素のindex """ self.calc=calc self.unit=unit self.index=index N=len(L) d=max(1,(N-1).bit_length()) k=1<1: m>>=1 self.data[m]=self.calc(self.data[m<<1],self.data[m<<1|1]) def product(self,From,To,index=1,left_closed=True,right_closed=True): L=(From-index)+self.N+(not left_closed) R=(To-index)+self.N+(right_closed) vL=self.unit vR=self.unit while L>=1 R>>=1 return self.calc(vL,vR) def all_product(self): return self.data[1] def max_right(self,left,cond,index=1): """以下の2つをともに満たすxの1つを返す.\n (1) x=left or cond(data[left]*data[left+1]*...*data[x-1]):True (2) x=N+index or cond(data[left]*data[left+1]*...*data[x]):False ※condが単調減少の時,cond(data[left]*...*data[x-1])を満たす最大のxとなる. cond:関数(引数が同じならば結果も同じ) cond(unit):True index<=left<=r>=1 if not cond(calc(sm,self.data[left])): while left1 and right&1: right>>=1 if not cond(calc(self.data[right],sm)): while right0: H.insert(x) else: H.erase(-x) A[i]=H.get_max() S=Segment_Tree(A,min,10**9,0) for L,R,B in M: if S.product(L,R,0)!=B: exit(print(-1)) print(*A[1:N+1])