結果

問題 No.1675 Strange Minimum Query
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-09-10 23:11:44
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,991 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 154,060 KB
最終ジャッジ日時 2023-09-02 21:25:03
合計ジャッジ時間 25,643 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,260 KB
testcase_01 AC 76 ms
71,336 KB
testcase_02 AC 75 ms
71,328 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 328 ms
97,264 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 555 ms
140,408 KB
testcase_14 AC 615 ms
153,644 KB
testcase_15 AC 692 ms
153,644 KB
testcase_16 AC 81 ms
71,260 KB
testcase_17 AC 407 ms
94,320 KB
testcase_18 AC 481 ms
98,688 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 968 ms
141,408 KB
testcase_23 RE -
testcase_24 AC 730 ms
120,588 KB
testcase_25 RE -
testcase_26 WA -
testcase_27 AC 765 ms
131,108 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 AC 1,233 ms
153,380 KB
testcase_33 AC 1,199 ms
152,532 KB
testcase_34 AC 1,234 ms
152,016 KB
testcase_35 AC 1,132 ms
154,060 KB
testcase_36 AC 1,169 ms
153,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmrntTree:
    
    def __init__(self,arr,func,i_ele):
        self.i_ele = i_ele
        self.func = func
        arr_len = len(arr)
        self.tree_len = 2 ** (arr_len-1).bit_length()  * 2
        self.tree = [i_ele] * self.tree_len
        for i in range(arr_len):
            self.tree[i + self.tree_len // 2] = arr[i]
        for i in range(self.tree_len // 2 -1,0,-1):
            self.tree[i] = func(self.tree[i * 2],self.tree[i * 2 + 1])
    
    def query_range(self,l,r):
        res = self.i_ele
        l += self.tree_len // 2 - 1
        r += self.tree_len // 2 
        while l < r:
            if l & 1:
                res = self.func(res,self.tree[l])
                l += 1
            if r & 1:
                res = self.func(res,self.tree[r-1])
                r -= 1
            l >>= 1
            r >>= 1
        return res
    
    def query(self,l):
        return self.tree[l + self.tree_len // 2 - 1]
    
    def update(self,l,x):
        l += self.tree_len // 2 - 1
        self.tree[l] = x
        def calc(l):
            if l & 1:
                l -=1
            return l >> 1
        while calc(l):
            if l & 1:
                self.tree[calc(l)] = self.func(self.tree[l],self.tree[l-1])
            else:
                self.tree[calc(l)] = self.func(self.tree[l],self.tree[l+1])
            l = calc(l)
n,q = map(int,input().split())
lis = [list(map(int,input().split())) for _ in range(q)]
tree = [0] * n
st = SegmrntTree(tree,max,0)
ll = [[] for _ in range(n)]
lr = [[] for _ in range(n+1)]
for i in range(q):
    l,r,b = lis[i]
    ll[l-1].append((i+1,b))
    lr[r].append(i+1)
B = [0] * n
for i in range(n):
    for l,b in ll[i]:
        st.update(l,b)
    for r in lr[i]:
        st.update(r,0)
    val = st.query_range(1,n)
    B[i] = val
flg = True
st = SegmrntTree(B,min,10**10)
for i in range(q):
    l,r,b = lis[i]
    val = st.query_range(l,r)
    if val != b:
        flg = False
if flg:
    print(*B)
else:
    print(-1)
0