結果
| 問題 |
No.2650 [Cherry 6th Tune *] セイジャク
|
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2024-02-23 22:09:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 913 ms / 2,500 ms |
| コード長 | 1,801 bytes |
| コンパイル時間 | 360 ms |
| コンパイル使用メモリ | 82,100 KB |
| 実行使用メモリ | 127,568 KB |
| 最終ジャッジ日時 | 2024-09-29 06:51:38 |
| 合計ジャッジ時間 | 25,457 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
class segtree:
def __init__(self,n):
self.size=1
self.height=0
while self.size<n:
self.size*=2
self.height+=1
self.dat=[-1]*(self.size*2)
self.lazy=[-1]*(self.size*2)
def lazyup(self,l,r,a):
l+=self.size
r+=self.size
while l<r:
if l&1:
self.lazy[l]=max(self.lazy[l],a)
l+=1
if r&1:
r-=1
self.lazy[r]=max(self.lazy[r],a)
l//=2
r//=2
def querry(self,l,r):
l+=self.size
r+=self.size
score=-10**20
while l<r:
if l&1:
w=max(self.dat[l],self.lazy[l])
score=max(score,w)
l+=1
if r&1:
r-=1
w=max(self.dat[r],self.lazy[r])
score=max(score,w)
l//=2
r//=2
return score
def propagate(self,x):
x+=self.size
for h in range(self.height,0,-1):
y=x>>h
self.lazy[2*y]=max(self.lazy[y],self.lazy[2*y])
self.lazy[2*y+1]=max(self.lazy[y],self.lazy[2*y+1])
self.dat[y]=max(self.dat[y],self.lazy[y])
self.lazy[y]=-1
def bottom(self,x):
x+=self.size
while x>1:
x//=2
self.dat[x]=max(max(self.dat[2*x],self.lazy[2*x]),max(self.dat[2*x+1],self.lazy[2*x+1]))
N,ppp=map(int,input().split())
A=list(map(int,input().split()))
B=set()
for i in range(N):
B.add(A[i])
B=list(B)
B.sort()
T={}
for i in range(len(B)):
T[B[i]]=i
M=len(B)
Z=segtree(M)
K=int(input())
from bisect import bisect_left,bisect_right
for t in range(1,K+1):
l,r=map(int,input().split())
pos1=bisect_left(B,l)
pos2=bisect_right(B,r)
Z.propagate(pos1)
Z.propagate(pos2-1)
Z.lazyup(pos1,pos2,t)
Z.bottom(pos1)
Z.bottom(pos2-1)
for i in range(N):
pos=T[A[i]]
Z.propagate(pos)
ans=Z.querry(pos,pos+1)
print(ans)
ゼット