結果

問題 No.1675 Strange Minimum Query
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-09-11 00:20:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,201 ms / 2,000 ms
コード長 1,991 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 154,188 KB
最終ジャッジ日時 2023-09-03 13:33:34
合計ジャッジ時間 29,620 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,252 KB
testcase_01 AC 74 ms
71,316 KB
testcase_02 AC 74 ms
71,264 KB
testcase_03 AC 775 ms
116,064 KB
testcase_04 AC 810 ms
121,152 KB
testcase_05 AC 316 ms
93,940 KB
testcase_06 AC 892 ms
120,992 KB
testcase_07 AC 1,022 ms
128,784 KB
testcase_08 AC 84 ms
75,572 KB
testcase_09 AC 147 ms
78,908 KB
testcase_10 AC 531 ms
121,892 KB
testcase_11 AC 278 ms
99,052 KB
testcase_12 AC 559 ms
125,552 KB
testcase_13 AC 539 ms
140,380 KB
testcase_14 AC 611 ms
153,520 KB
testcase_15 AC 680 ms
153,608 KB
testcase_16 AC 79 ms
71,400 KB
testcase_17 AC 414 ms
93,972 KB
testcase_18 AC 518 ms
101,288 KB
testcase_19 AC 595 ms
115,736 KB
testcase_20 AC 835 ms
129,308 KB
testcase_21 AC 790 ms
130,000 KB
testcase_22 AC 935 ms
141,312 KB
testcase_23 AC 778 ms
118,668 KB
testcase_24 AC 740 ms
120,036 KB
testcase_25 AC 587 ms
107,136 KB
testcase_26 AC 480 ms
101,440 KB
testcase_27 AC 772 ms
128,800 KB
testcase_28 AC 501 ms
110,260 KB
testcase_29 AC 461 ms
108,876 KB
testcase_30 AC 436 ms
99,712 KB
testcase_31 AC 944 ms
127,280 KB
testcase_32 AC 1,201 ms
154,188 KB
testcase_33 AC 1,197 ms
151,768 KB
testcase_34 AC 1,173 ms
151,876 KB
testcase_35 AC 1,117 ms
153,672 KB
testcase_36 AC 1,139 ms
153,656 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 = [1] * q
st = SegmrntTree(tree,max,1)
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 = [1] * 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,q)
    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