結果

問題 No.1675 Strange Minimum Query
ユーザー chineristACchineristAC
提出日時 2021-09-10 21:36:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 805 ms / 2,000 ms
コード長 2,336 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 118,400 KB
最終ジャッジ日時 2023-09-02 16:15:15
合計ジャッジ時間 21,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
71,804 KB
testcase_01 AC 100 ms
72,112 KB
testcase_02 AC 98 ms
72,100 KB
testcase_03 AC 381 ms
98,720 KB
testcase_04 AC 369 ms
99,320 KB
testcase_05 AC 194 ms
85,064 KB
testcase_06 AC 434 ms
101,796 KB
testcase_07 AC 443 ms
105,404 KB
testcase_08 AC 100 ms
76,096 KB
testcase_09 AC 129 ms
78,128 KB
testcase_10 AC 320 ms
100,840 KB
testcase_11 AC 239 ms
92,564 KB
testcase_12 AC 329 ms
102,228 KB
testcase_13 AC 413 ms
114,936 KB
testcase_14 AC 485 ms
118,400 KB
testcase_15 AC 505 ms
118,368 KB
testcase_16 AC 110 ms
71,864 KB
testcase_17 AC 297 ms
86,604 KB
testcase_18 AC 326 ms
87,936 KB
testcase_19 AC 368 ms
97,368 KB
testcase_20 AC 539 ms
106,108 KB
testcase_21 AC 511 ms
104,600 KB
testcase_22 AC 622 ms
109,620 KB
testcase_23 AC 506 ms
98,824 KB
testcase_24 AC 481 ms
99,392 KB
testcase_25 AC 407 ms
92,640 KB
testcase_26 AC 311 ms
89,912 KB
testcase_27 AC 462 ms
102,924 KB
testcase_28 AC 384 ms
96,676 KB
testcase_29 AC 304 ms
94,956 KB
testcase_30 AC 312 ms
89,244 KB
testcase_31 AC 621 ms
105,352 KB
testcase_32 AC 805 ms
115,740 KB
testcase_33 AC 768 ms
116,408 KB
testcase_34 AC 734 ms
116,420 KB
testcase_35 AC 722 ms
116,172 KB
testcase_36 AC 635 ms
116,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class DualSegmentTree:
    def __init__(self, n, segfunc, ide_ele):
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num

    def update(self,l,r,x):
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                self.tree[l] = self.segfunc(self.tree[l],x)
                l += 1
            if r & 1:
                self.tree[r-1] = self.segfunc(self.tree[r-1],x)
            l >>= 1
            r >>= 1

    def __getitem__(self,idx):
        idx += self.num
        res = self.ide_ele
        while idx:
            res = self.segfunc(res,self.tree[idx])
            idx>>=1
        return res

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

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

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        right = []
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                right.append(self.tree[r-1])
            l >>= 1
            r >>= 1

        for e in right[::-1]:
            res = self.segfunc(res,e)
        return res

import sys,random

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,Q = mi()
A = DualSegmentTree(N,max,1)
query = [tuple(mi()) for i in range(Q)]
for l,r,b in query:
    A.update(l-1,r,b)

res = [A[i] for i in range(N)]
#print(res)
Seg = SegmentTree(res,min,10**17)
for l,r,b in query:
    if Seg.query(l-1,r)!=b:
        #print(Seg.query(l-1,r),b)
        exit(print(-1))

print(*res)
0