結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 72 ms
71,652 KB
testcase_03 AC 795 ms
116,168 KB
testcase_04 AC 826 ms
121,156 KB
testcase_05 RE -
testcase_06 AC 844 ms
121,444 KB
testcase_07 AC 952 ms
128,524 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 AC 529 ms
140,660 KB
testcase_14 AC 585 ms
153,324 KB
testcase_15 AC 664 ms
153,504 KB
testcase_16 AC 73 ms
71,236 KB
testcase_17 AC 382 ms
93,424 KB
testcase_18 AC 465 ms
98,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 AC 930 ms
140,804 KB
testcase_23 WA -
testcase_24 AC 699 ms
120,320 KB
testcase_25 WA -
testcase_26 RE -
testcase_27 AC 729 ms
127,952 KB
testcase_28 WA -
testcase_29 RE -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1,179 ms
153,372 KB
testcase_33 AC 1,143 ms
152,660 KB
testcase_34 AC 1,229 ms
151,884 KB
testcase_35 AC 1,062 ms
154,068 KB
testcase_36 AC 1,103 ms
153,036 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] * q
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