結果

問題 No.1675 Strange Minimum Query
ユーザー mkawa2mkawa2
提出日時 2021-09-10 22:00:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 924 ms / 2,000 ms
コード長 1,918 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 192,056 KB
最終ジャッジ日時 2023-09-02 17:35:41
合計ジャッジ時間 22,470 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,192 KB
testcase_01 AC 73 ms
71,268 KB
testcase_02 AC 76 ms
71,192 KB
testcase_03 AC 543 ms
130,868 KB
testcase_04 AC 632 ms
139,016 KB
testcase_05 AC 233 ms
106,768 KB
testcase_06 AC 614 ms
141,348 KB
testcase_07 AC 651 ms
151,496 KB
testcase_08 AC 74 ms
71,348 KB
testcase_09 AC 106 ms
78,068 KB
testcase_10 AC 336 ms
136,672 KB
testcase_11 AC 186 ms
112,760 KB
testcase_12 AC 367 ms
143,428 KB
testcase_13 AC 367 ms
178,784 KB
testcase_14 AC 442 ms
190,136 KB
testcase_15 AC 515 ms
192,056 KB
testcase_16 AC 76 ms
71,688 KB
testcase_17 AC 285 ms
98,408 KB
testcase_18 AC 321 ms
103,932 KB
testcase_19 AC 415 ms
134,084 KB
testcase_20 AC 614 ms
154,272 KB
testcase_21 AC 795 ms
156,800 KB
testcase_22 AC 673 ms
173,008 KB
testcase_23 AC 585 ms
134,076 KB
testcase_24 AC 563 ms
140,808 KB
testcase_25 AC 453 ms
116,196 KB
testcase_26 AC 315 ms
107,380 KB
testcase_27 AC 513 ms
153,240 KB
testcase_28 AC 375 ms
125,796 KB
testcase_29 AC 317 ms
126,016 KB
testcase_30 AC 317 ms
109,464 KB
testcase_31 AC 662 ms
147,032 KB
testcase_32 AC 890 ms
191,828 KB
testcase_33 AC 879 ms
189,408 KB
testcase_34 AC 894 ms
191,344 KB
testcase_35 AC 904 ms
182,608 KB
testcase_36 AC 924 ms
182,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**20
md = 998244353
# md = 10**9+7

class SparseTableMin:
    def __init__(self, aa):
        w = len(aa)
        h = w.bit_length()
        table = [aa]+[[-1]*w for _ in range(h-1)]
        tablei1 = table[0]
        for i in range(1, h):
            tablei = table[i]
            for j in range(w-(1 << i)+1):
                rj = j+(1 << (i-1))
                tablei[j] = min(tablei1[j], tablei1[rj])
            tablei1 = tablei
        self.table = table

    # [l,r)の最小値
    def min(self, l, r):
        i = (r-l).bit_length()-1
        tablei = self.table[i]
        Lmin = tablei[l]
        Rmin = tablei[r-(1 << i)]
        if Lmin < Rmin: Rmin = Lmin
        return Rmin

from heapq import *

mx = 10**9

n, q = LI()
aa = [mx]*n
lrb = []
ltorb = [[] for _ in range(n+1)]
rtob = [[] for _ in range(n+1)]
for _ in range(q):
    l, r, b = LI()
    l -= 1
    lrb.append((l, r, b))
    ltorb[l].append((r, b))
    rtob[r].append(b)

hp = []
rem = []

aa = [mx]*n
for i in range(n):
    for b in rtob[i]:
        heappush(rem, -b)
    while hp and rem and hp[0] == rem[0]:
        heappop(hp)
        heappop(rem)
    for r, b in ltorb[i]:
        heappush(hp, -b)
    if not hp: continue
    aa[i] = -hp[0]

sp = SparseTableMin(aa)
for l, r, b in lrb:
    if sp.min(l, r) != b:
        print(-1)
        exit()

print(*aa)
0