結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 rin204rin204
提出日時 2021-09-18 10:30:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,126 ms / 2,000 ms
コード長 2,118 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 161,308 KB
最終ジャッジ日時 2023-09-12 19:59:20
合計ジャッジ時間 29,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,136 KB
testcase_01 AC 73 ms
71,152 KB
testcase_02 AC 72 ms
71,176 KB
testcase_03 AC 577 ms
131,096 KB
testcase_04 AC 635 ms
128,628 KB
testcase_05 AC 207 ms
89,584 KB
testcase_06 AC 653 ms
141,740 KB
testcase_07 AC 683 ms
148,724 KB
testcase_08 AC 74 ms
71,188 KB
testcase_09 AC 114 ms
77,764 KB
testcase_10 AC 535 ms
113,788 KB
testcase_11 AC 199 ms
94,064 KB
testcase_12 AC 516 ms
117,344 KB
testcase_13 AC 387 ms
144,412 KB
testcase_14 AC 502 ms
160,188 KB
testcase_15 AC 560 ms
159,000 KB
testcase_16 AC 73 ms
70,760 KB
testcase_17 AC 324 ms
92,372 KB
testcase_18 AC 383 ms
96,364 KB
testcase_19 AC 420 ms
108,152 KB
testcase_20 AC 704 ms
132,004 KB
testcase_21 AC 659 ms
129,640 KB
testcase_22 AC 767 ms
141,704 KB
testcase_23 AC 688 ms
125,144 KB
testcase_24 AC 652 ms
122,040 KB
testcase_25 AC 511 ms
108,720 KB
testcase_26 AC 349 ms
97,004 KB
testcase_27 AC 568 ms
124,204 KB
testcase_28 AC 408 ms
106,628 KB
testcase_29 AC 322 ms
102,484 KB
testcase_30 AC 344 ms
98,028 KB
testcase_31 AC 792 ms
138,628 KB
testcase_32 AC 1,126 ms
160,536 KB
testcase_33 AC 1,038 ms
158,920 KB
testcase_34 AC 1,048 ms
161,308 KB
testcase_35 AC 1,004 ms
152,520 KB
testcase_36 AC 1,038 ms
153,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
class SegTree():
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def f5(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
            
        res = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                res = self.ope(res, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                res = self.ope(res, self.data[r])
            l >>= 1
            r >>= 1
        return res
            
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n, q = map(int, input().split())
query = []
imos = [[] for _ in range(n + 1)]
for _ in range(q):
    l, r, b = map(int, input().split())
    query.append((l, r, b))
    imos[l - 1].append((b, 1))
    imos[r].append((b, 2))

alst = [-1] * n
hq = [-1]
rem = []
for i in range(n):
    for b, t in imos[i]:
        if t == 1:
            heappush(hq, -b)
        else:
            heappush(rem, -b)
    while rem and rem[0] == hq[0]:
        heappop(rem)
        heappop(hq)
    alst[i] = -hq[0]
    
inf = 10 ** 10
e = inf
def ope(x, y):
    return min(x, y)
seg = SegTree(n, e, ope, alst)
for l, r, x in query:
    if seg.query(l - 1, r) != x:
        print(-1)
        exit()

print(*alst)

0