結果

問題 No.1675 Strange Minimum Query
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-11-08 19:47:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,401 ms / 2,000 ms
コード長 4,883 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 119,888 KB
最終ジャッジ日時 2024-11-16 18:54:54
合計ジャッジ時間 34,188 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,032 KB
testcase_01 AC 36 ms
54,408 KB
testcase_02 AC 37 ms
53,164 KB
testcase_03 AC 780 ms
98,976 KB
testcase_04 AC 807 ms
100,560 KB
testcase_05 AC 393 ms
87,276 KB
testcase_06 AC 842 ms
101,844 KB
testcase_07 AC 966 ms
106,208 KB
testcase_08 AC 56 ms
66,940 KB
testcase_09 AC 137 ms
77,512 KB
testcase_10 AC 424 ms
102,076 KB
testcase_11 AC 298 ms
94,336 KB
testcase_12 AC 445 ms
103,616 KB
testcase_13 AC 539 ms
114,572 KB
testcase_14 AC 730 ms
118,988 KB
testcase_15 AC 604 ms
117,952 KB
testcase_16 AC 40 ms
53,512 KB
testcase_17 AC 559 ms
88,664 KB
testcase_18 AC 626 ms
90,348 KB
testcase_19 AC 699 ms
100,392 KB
testcase_20 AC 1,042 ms
109,300 KB
testcase_21 AC 987 ms
108,032 KB
testcase_22 AC 1,143 ms
112,152 KB
testcase_23 AC 999 ms
99,584 KB
testcase_24 AC 984 ms
102,016 KB
testcase_25 AC 810 ms
94,248 KB
testcase_26 AC 588 ms
92,660 KB
testcase_27 AC 929 ms
106,996 KB
testcase_28 AC 670 ms
100,480 KB
testcase_29 AC 585 ms
98,508 KB
testcase_30 AC 583 ms
91,732 KB
testcase_31 AC 1,175 ms
107,632 KB
testcase_32 AC 1,361 ms
118,964 KB
testcase_33 AC 1,349 ms
119,284 KB
testcase_34 AC 1,401 ms
119,356 KB
testcase_35 AC 1,326 ms
119,808 KB
testcase_36 AC 1,364 ms
119,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
class LazySegTree:

    def __init__(self, n, op, e, mapping, composition, id):
        self.n = n
        self.op = op
        self.e = e
        self.mapping = mapping
        self.composition = composition
        self.id = id
        self.log = (n-1).bit_length()
        self.size = 1 << self.log
        self.data = [e]*(2*self.size)
        self.lazy = [id]*(self.size)

    def update(self, k):
        self.data[k] = self.op(self.data[2*k],self.data[2*k+1])

    def build(self, lis):
        for i, l in enumerate(lis,self.size):
            self.data[i] = l
        for i in range(self.size-1, 0, -1):
            self.update(i)

    def point_set(self, p, x):
        p += self.size
        for i in range(self.log, 0, -1):
            self.push(p >> i)
        self.data[p] = x
        for i in range(1,self.log+1):
            self.update(p>>i)

    def point_get(self, p):
        p += self.size
        for i in range(self.log, 0,-1):
            self.push(p >> i)
        return self.data[p]

    def apply(self, p, f):
        p += self.size
        for i in range(self.log, 0, -1):
            self.push(p >> i)
        self.data[p] = self.mapping(f, self.data[p])
        for i in range(1, self.log+1):
            self.update(p >> i)

    def range_apply(self, l, r, f):
        ''' change the value you define in "mapping" and "composition" of [l,r) '''
        if l == r:
            return 
        l += self.size
        r += self.size
        for i in range(self.log, 0, -1):
            if ((l >> i) << i) != l:
                self.push(l >> i)
            if ((r >> i) << i) != r:
                self.push((r-1) >> i)
        l2 = l
        r2 = r
        while l2 < r2:
            if l2 & 1:
                self.all_apply(l2, f)
                l2 += 1
            if r2 & 1:
                r2 -= 1
                self.all_apply(r2, f)
            l2 >>= 1
            r2 >>= 1
        for i in range(1, self.log+1):
            if ((l >> i) << i) != l:
                self.update(l >> i)
            if ((r >> i) << i) != r:
                self.update((r-1) >> i)

    def all_apply(self, k, f):
        self.data[k] = self.mapping(f, self.data[k])
        if k < self.size:
            self.lazy[k] = self.composition(f, self.lazy[k])

    def push(self, k):
        self.all_apply(2*k, self.lazy[k])
        self.all_apply(2*k+1, self.lazy[k])
        self.lazy[k] = self.id

    def prod(self, l, r):
        ''' get the value you define in "op" of [l,r) '''
        if l == r:
            return self.e
        l += self.size
        r += self.size
        for i in range(self.log, 0, -1):
            if ((l>>i) <<i) != l:
                self.push(l>>i)
            if ((r>>i) <<i) != r:
                self.push(r>>i)
        sml = smr = 10**10
        while l < r:
            if l & 1:
                sml = self.op(sml, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.data[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        return self.data[1]


def op(x, y):
    return max(x,y)

def mapping(p, x):
    return max(x,p)

def composition(p, q):
    return max(p,q)

class SegTree:
    """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """
    
    def __init__(self,size,func,sta):
        self.n = size
        self.size = 1 << size.bit_length()
        self.func = func
        self.sta = sta
        self.tree = [sta]*(2*self.size)

    def build(self, list):
        """ set list and update tree"""
        for i,x in enumerate(list,self.size):
            self.tree[i] = x

        for i in range(self.size-1,0,-1):
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    def set(self,i,x):
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    
    def get(self,l,r):
        """ take the value of [l r) with func (min or max)"""
        l += self.size
        r += self.size
        res = self.sta

        while l < r:
            if l & 1:
                res = self.func(self.tree[l],res)
                l += 1
            if r & 1:
                res = self.func(self.tree[r-1],res)
            l >>= 1
            r >>= 1
        return res

def f(x,y):
    return min(x,y)
e = 1
id = 0
n,q = map(int,input().split())
lazyseg = LazySegTree(n, op, e, mapping, composition, id)

Q = [list(map(int,input().split())) for i in range(q)]
for l,r,b in Q:
    lazyseg.range_apply(l-1,r,b)
ans = [lazyseg.point_get(i) for i in range(n)]
seg = SegTree(n,f,10**9)
seg.build(ans)
for l,r,b in Q:
    if seg.get(l-1,r) != b:
        print(-1)
        exit()

print(*ans)
0