結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 Kazun
提出日時 2021-09-10 21:47:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 9,967 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 133,308 KB
最終ジャッジ日時 2024-06-11 23:21:06
合計ジャッジ時間 29,112 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

class Lazy_Evaluation_Tree():
def __init__(self,L,calc,unit,op,comp,id,index):
"""calc,opLSegment Tree
calc:
unit:calc (xe=ex=xe)
op:
comp:
id:
[] M:Monoid,F={f:F x M→ M:},.
F id ., x in M id(x)=x
F., f,g in F , comp(f,g) in F
f in F, x,y in M ,f(xy)=f(x)f(y).
[]
..
"""
self.calc=calc
self.unit=unit
self.op=op
self.comp=comp
self.id=id
self.index=index
N=len(L)
d=max(1,(N-1).bit_length())
k=1<<d
self.data=[unit]*k+L+[unit]*(k-len(L))
self.lazy=[self.id]*(2*k)
self.N=k
self.depth=d
for i in range(k-1,0,-1):
self.data[i]=calc(self.data[i<<1],self.data[i<<1|1])
def _eval_at(self,m):
if self.lazy[m]==self.id:
return self.data[m]
return self.op(self.lazy[m],self.data[m])
#m
def _propagate_at(self,m):
self.data[m]=self._eval_at(m)
if m<self.N and self.lazy[m]!=self.id:
self.lazy[m<<1]=self.comp(
self.lazy[m],
self.lazy[m<<1]
)
self.lazy[m<<1|1]=self.comp(
self.lazy[m],
self.lazy[m<<1|1]
)
self.lazy[m]=self.id
#m
def _propagate_above(self,m):
H=m.bit_length()
for h in range(H-1,0,-1):
self._propagate_at(m>>h)
#m
def _recalc_above(self,m):
while m>1:
m>>=1
self.data[m]=self.calc(
self._eval_at(m<<1),
self._eval_at(m<<1|1)
)
def get(self,k):
index=self.index
m=k-index+self.N
self._propagate_above(m)
self.data[m]=self._eval_at(m)
self.lazy[m]=self.id
return self.data[m]
#
def operate(self,From,To,alpha,left_closed=True,right_closed=True):
index=self.index
L=(From-index)+self.N+(not left_closed)
R=(To-index)+self.N+(right_closed)
L0=R0=-1
X,Y=L,R-1
while X<Y:
if X&1:
L0=max(L0,X)
X+=1
if Y&1==0:
R0=max(R0,Y)
Y-=1
X>>=1
Y>>=1
L0=max(L0,X)
R0=max(R0,Y)
self._propagate_above(L0)
self._propagate_above(R0)
while L<R:
if L&1:
self.lazy[L]=self.comp(alpha,self.lazy[L])
L+=1
if R&1:
R-=1
self.lazy[R]=self.comp(alpha,self.lazy[R])
L>>=1
R>>=1
self._recalc_above(L0)
self._recalc_above(R0)
def update(self,k,x):
""" kx.
"""
index=self.index
m=k-index+self.N
self._propagate_above(m)
self.data[m]=x
self.lazy[m]=self.id
self._recalc_above(m)
def product(self,From,To,left_closed=True,right_closed=True):
index=self.index
L=(From-index)+self.N+(not left_closed)
R=(To-index)+self.N+(right_closed)
L0=R0=-1
X,Y=L,R-1
while X<Y:
if X&1:
L0=max(L0,X)
X+=1
if Y&1==0:
R0=max(R0,Y)
Y-=1
X>>=1
Y>>=1
L0=max(L0,X)
R0=max(R0,Y)
self._propagate_above(L0)
self._propagate_above(R0)
vL=vR=self.unit
while L<R:
if L&1:
vL=self.calc(vL,self._eval_at(L))
L+=1
if R&1:
R-=1
vR=self.calc(self._eval_at(R),vR)
L>>=1
R>>=1
return self.calc(vL,vR)
def all_product(self):
return self.product(1,self.N,1)
#
def refresh(self):
for m in range(1,2*self.N):
self.data[m]=self._eval_at(m)
if m<self.N and self.lazy[m]!=self.id:
self.lazy[m<<1]=self.comp(
self.lazy[m],
self.lazy[m<<1]
)
self.lazy[m<<1|1]=self.comp(
self.lazy[m],
self.lazy[m<<1|1]
)
self.lazy[m]=self.id
def __getitem__(self,k):
return self.get(k)
def __setitem__(self,k,x):
self.update(k,x)
class Segment_Tree():
"""
1-index
"""
def __init__(self,L,calc,unit,index):
"""calcLSegment Tree
calc:(2,)
unit:calc (xe=ex=xe)
index:1index
"""
self.calc=calc
self.unit=unit
self.index=index
N=len(L)
d=max(1,(N-1).bit_length())
k=1<<d
self.data=[unit]*k+L+[unit]*(k-len(L))
self.N=k
self.depth=d
for i in range(k-1,0,-1):
self.data[i]=self.calc(self.data[i<<1],self.data[i<<1|1])
def get(self,k,index=1):
"""k
"""
assert 0<=k-index<self.N,""
return self.data[k-index+self.N]
def update(self,k,x,index=1):
"""kx,.
k:
x:
"""
assert 0<=k-index<self.N,""
m=(k-index)+self.N
self.data[m]=x
while m>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<R:
if L&1:
vL=self.calc(vL,self.data[L])
L+=1
if R&1:
R-=1
vR=self.calc(self.data[R],vR)
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):
"""2x1.\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<n+index
"""
left-=index
assert 0<=left<=self.N,""
assert cond(self.unit),"."
if left==self.N:
return self.N+index
left+=self.N-(index-1)
sm=self.unit
calc=self.calc
first=True
while first or (left & (-left))!=left:
first=False
while left%2==0:
left>>=1
if not cond(calc(sm,self.data[left])):
while left<self.N:
left<<=1
if cond(self.calc(sm,self.data[left])):
sm=self.calc(sm,self.data[left])
left+=1
return left-self.N+index
sm=self.calc(sm,self.data[left])
left+=1
return self.N+index
def min_left(self,right,cond,index=1):
"""2y1.\n
(1) y=right or cond(data[y]*data[y+1]*...*data[right]):True
(2) y=index or cond(data[y-1]*data[y]*...*data[right]):False
※cond調,cond(data[y]*...*data[right-1])y.
cond:()
cond(unit):True
index<=left<=r<n+index
"""
right-=index
assert 0<=right<=self.N,""
assert cond(self.unit),"."
if right==0:
return index
right+=self.N
sm=self.unit
calc=self.calc
first=1
while first or (right & (-right))!=right:
first=0
right-=1
while right>1 and right&1:
right>>=1
if not cond(calc(self.data[right],sm)):
while right<self.N:
right=2*right+1
if cond(calc(self.data[right],sm)):
sm=calc(self.data[right],sm)
right-=1
return right+1-self.N+index
sm=calc(self.data[right],sm)
return index
def __getitem__(self,k):
return self.get(k,self.index)
def __setitem__(self,k,x):
return self.update(k,x,self.index)
#================================================
import sys
from heapq import heapify,heappop,heappush
input=sys.stdin.readline
N,Q=map(int,input().split())
P=[]
for _ in range(Q):
l,r,b=map(int,input().split())
P.append((l-1,r-1,b))
S=Lazy_Evaluation_Tree([1]*N,max,1,max,max,-1,0)
for l,r,b in P:
S.operate(l,r,b)
S.refresh()
X=[S[i] for i in range(N)]
T=Segment_Tree(X,min,10**9,0)
for l,r,b in P:
if T.product(l+1,r)!=b:
exit(print(-1))
print(*X)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0