結果

問題 No.1675 Strange Minimum Query
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-09-10 23:44:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,658 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 127,468 KB
最終ジャッジ日時 2023-09-02 23:29:40
合計ジャッジ時間 45,855 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,316 KB
testcase_01 AC 69 ms
71,196 KB
testcase_02 AC 70 ms
71,388 KB
testcase_03 AC 911 ms
100,248 KB
testcase_04 AC 826 ms
98,296 KB
testcase_05 AC 327 ms
86,440 KB
testcase_06 AC 1,073 ms
110,364 KB
testcase_07 AC 1,077 ms
105,564 KB
testcase_08 WA -
testcase_09 AC 170 ms
80,124 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 959 ms
116,484 KB
testcase_15 AC 777 ms
115,616 KB
testcase_16 AC 69 ms
71,020 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,498 ms
110,516 KB
testcase_24 WA -
testcase_25 AC 1,269 ms
102,848 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,671 ms
117,004 KB
testcase_32 TLE -
testcase_33 WA -
testcase_34 TLE -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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(1, self.log+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 min(x,y)

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

def composition(p, q):
    return max(p,q)
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)]
Q.sort(key=lambda x: x[2])

for l,r,b in Q:
    lazyseg.range_apply(l-1,r,b)
for l,r,b in Q:
    if lazyseg.prod(l-1,r) != b:
        print(-1)
        exit()
ans = [lazyseg.point_get(i) for i in range(n)]
print(*ans)
0