結果

問題 No.1675 Strange Minimum Query
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-10 21:44:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,844 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 127,716 KB
最終ジャッジ日時 2023-09-02 16:39:28
合計ジャッジ時間 23,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,068 KB
testcase_01 AC 76 ms
71,104 KB
testcase_02 AC 76 ms
71,064 KB
testcase_03 AC 385 ms
103,136 KB
testcase_04 AC 325 ms
98,252 KB
testcase_05 AC 96 ms
79,976 KB
testcase_06 AC 432 ms
105,468 KB
testcase_07 AC 448 ms
107,712 KB
testcase_08 AC 75 ms
71,336 KB
testcase_09 AC 108 ms
76,988 KB
testcase_10 AC 351 ms
102,876 KB
testcase_11 AC 192 ms
90,072 KB
testcase_12 AC 370 ms
104,024 KB
testcase_13 AC 354 ms
122,688 KB
testcase_14 AC 399 ms
126,768 KB
testcase_15 WA -
testcase_16 AC 78 ms
71,052 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        lres = self.ide_ele
        rres = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                rres = self.segfunc(self.seg[r], rres)
            if l & 1:
                lres = self.segfunc(lres, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        res = self.segfunc(lres, rres)
        return res

    def __str__(self): # for debug
        arr = [self.query(i,i+1) for i in range(self.n)]
        return str(arr)

INF = 10**18

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, q = map(int, input().split())
LR = []
for i in range(q):
    l, r, b = map(int, input().split())
    l, r = l-1, r-1
    LR.append((l, r, b))
seg = SegTree([INF]*n, INF, min)
LR.sort(key=lambda x: x[1])
#print(LR)
for l, r, b in LR:
    x = seg.query(l, r+1)
    if x < b:
        print(-1)
        exit()
    seg.update(l, b)
A = []
for i in range(n):
    a = seg.query(i, i+1)
    if a == INF:
        A.append(10**9)
    else:
        A.append(a)
print(*A)
0