結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2021-09-10 21:43:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,014 ms / 2,000 ms |
| コード長 | 1,943 bytes |
| コンパイル時間 | 220 ms |
| コンパイル使用メモリ | 81,936 KB |
| 実行使用メモリ | 156,716 KB |
| 最終ジャッジ日時 | 2024-06-11 23:07:32 |
| 合計ジャッジ時間 | 22,210 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
"""
Bが大きいほうから見ていけばよい?
各箇所に関して、置いてもよい最小の値は決まる
さて、後は置いていくだけの問題かな?
現状持っている区間のうち、最大を置いていく。
"""
import sys
from sys import stdin
import heapq
#0-indexed , 半開区間[a,b)
#calc変更で演算変更
class SegTree:
def __init__(self,N,first):
self.NO = 2**(N-1).bit_length()
self.First = first
self.data = [first] * (2*self.NO)
def calc(self,l,r):
return min(l,r)
def update(self,ind,x):
ind += self.NO - 1
self.data[ind] = x
while ind >= 0:
ind = (ind - 1)//2
self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2])
def query(self,l,r):
L = l + self.NO
R = r + self.NO
s = self.First
while L < R:
if R & 1:
R -= 1
s = self.calc(s , self.data[R-1])
if L & 1:
s = self.calc(s , self.data[L-1])
L += 1
L >>= 1
R >>= 1
return s
def get(self , ind):
ind += self.NO - 1
return self.data[ind]
N,Q = map(int,stdin.readline().split())
lrb = []
LtoRB = [ [] for i in range(N) ]
for i in range(Q):
l,r,b = map(int,stdin.readline().split())
l -= 1
r -= 1
lrb.append( (l,r,b) )
LtoRB[l].append( (r,b) )
lis = [None] * N
brq = []
for l in range(N):
for r,b in LtoRB[l]:
heapq.heappush( brq , (-b,r) )
while len(brq) > 0 and brq[0][1] < l:
heapq.heappop( brq )
if len(brq) == 0:
lis[l] = 1
else:
lis[l] = -1 * brq[0][0]
ST = SegTree(N,float("inf"))
for i in range(N):
ST.update(i,lis[i])
flag = True
for l,r,b in lrb:
if ST.query(l,r+1) != b:
flag = False
break
if flag:
print (*lis)
else:
print (-1)
SPD_9X2