結果

問題 No.1558 Derby Live
ユーザー 👑 Kazun
提出日時 2021-06-25 21:51:28
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 5,336 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 114,568 KB
最終ジャッジ日時 2024-06-25 08:23:49
合計ジャッジ時間 10,379 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 15 RE * 17
権限があれば一括ダウンロードができます

ソースコード

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

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)
#==================================================
def calc(x,y):
return [y[x[i]] for i in range(N+1)]
#==================================================
import sys
from operator import add
input=sys.stdin.readline
write=sys.stdout.write
N,M,Q=map(int,input().split())
unit=list(range(N+1))
Rank=Segment_Tree([unit for _ in range(M+1)],calc,unit,0)
Ans=[]
for _ in range(Q):
T,*Query=map(int,input().split())
if T==1:
D,*P=Query
Rank.update(D,[0]+P,0)
elif T==2:
S,=Query
P=Rank.product(1,S,0)[1:]
H=[0]*(N+1)
for i in range(1,N+1):
H[P[i-1]]=i
Ans.append(" ".join(map(str,H[1:])))
else:
L,R=Query
P=Rank.product(1,S,0)[1:]
K=0
for i in range(1,N+1):
K+=abs(i-P[i-1])
Ans.append(str(K))
write("\n".join(Ans))
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0