結果

問題 No.1675 Strange Minimum Query
ユーザー rlangevinrlangevin
提出日時 2023-04-25 00:28:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,563 ms / 2,000 ms
コード長 4,425 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 128,756 KB
最終ジャッジ日時 2024-04-26 10:24:24
合計ジャッジ時間 31,810 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,736 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 41 ms
52,736 KB
testcase_03 AC 866 ms
95,272 KB
testcase_04 AC 779 ms
94,912 KB
testcase_05 AC 195 ms
83,000 KB
testcase_06 AC 1,031 ms
98,388 KB
testcase_07 AC 1,126 ms
100,580 KB
testcase_08 AC 49 ms
60,544 KB
testcase_09 AC 109 ms
76,928 KB
testcase_10 AC 697 ms
107,084 KB
testcase_11 AC 339 ms
98,748 KB
testcase_12 AC 759 ms
109,888 KB
testcase_13 AC 878 ms
111,444 KB
testcase_14 AC 727 ms
110,008 KB
testcase_15 AC 1,178 ms
128,756 KB
testcase_16 AC 40 ms
52,480 KB
testcase_17 AC 383 ms
84,556 KB
testcase_18 AC 451 ms
85,904 KB
testcase_19 AC 644 ms
104,420 KB
testcase_20 AC 1,095 ms
103,468 KB
testcase_21 AC 1,033 ms
106,532 KB
testcase_22 AC 1,058 ms
108,856 KB
testcase_23 AC 863 ms
90,700 KB
testcase_24 AC 846 ms
96,032 KB
testcase_25 AC 627 ms
87,428 KB
testcase_26 AC 439 ms
89,668 KB
testcase_27 AC 900 ms
107,312 KB
testcase_28 AC 501 ms
99,364 KB
testcase_29 AC 534 ms
101,988 KB
testcase_30 AC 425 ms
89,848 KB
testcase_31 AC 1,059 ms
95,456 KB
testcase_32 AC 1,476 ms
112,696 KB
testcase_33 AC 1,563 ms
111,860 KB
testcase_34 AC 1,540 ms
112,604 KB
testcase_35 AC 1,192 ms
112,908 KB
testcase_36 AC 1,225 ms
112,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

class LazySegmentTree:
    def __init__(
        self,
        n,
        indentity_e_node,
        indentity_e_lazy,
        combine_node_f,
        combine_lazy_f,
        reflect_f,        
    ):
        self._n = n
        self._size = 1
        self._height = 0
        while self._size < self._n:
            self._size <<= 1
            self._height += 1
        self._indentity_e_node = indentity_e_node
        self._indentity_e_lazy = indentity_e_lazy
        self._combine_node_f = combine_node_f
        self._combine_lazy_f = combine_lazy_f
        self._reflect_f = reflect_f
        self._node = [self._indentity_e_node] * (2 * self._size)
        self._lazy = [self._indentity_e_lazy] * (2 * self._size)
        
    #遅延データの値を値データに反映させたときの値を返す。
    def _reflect_lazy(self, index):
        return self._reflect_f(self._node[index], self._lazy[index])
    
    def _propagate_from_top(self, index):
        index += self._size
        for h in range(self._height, 0, -1):
            i = index >> h
            if self._lazy[i] != self._indentity_e_lazy:
                self._lazy[i << 1] = self._combine_lazy_f(
                    self._lazy[i << 1], self._lazy[i]
                )
                self._lazy[i << 1 | 1] = self._combine_lazy_f(
                    self._lazy[i << 1 | 1], self._lazy[i]
                )
                
                self._node[i] = self._reflect_lazy(i)
                self._lazy[i] = self._indentity_e_lazy
                
    def _update_from_bottom(self, index):
        index = (index + self._size) >> 1
        while index:
            self._node[index] = self._combine_node_f(
                self._reflect_lazy(index << 1),
                self._reflect_lazy(index << 1 | 1)                
            )
            index >>= 1
            
    def build(self, array):
        assert len(array) == self._n
        for index, value in enumerate(array, start=self._size):
            self._node[index] = value
        for index in range(self._size - 1, 0, -1):
            self._node[index] = self._combine_node_f(
                self._node[index << 1],
                self._node[index << 1 | 1]    
            )
            
    # 区間更新 位置[L, R) (0-indexed)を値valueで更新
    def update(self, L, R, value):
        self._propagate_from_top(L)
        self._propagate_from_top(R - 1)
        
        L_lazy = L + self._size
        R_lazy = R + self._size
        while L_lazy < R_lazy:
            if L_lazy & 1:
                self._lazy[L_lazy] = self._combine_lazy_f(self._lazy[L_lazy], value)
                L_lazy += 1
            if R_lazy & 1:
                R_lazy -= 1
                self._lazy[R_lazy] = self._combine_lazy_f(self._lazy[R_lazy], value)
            L_lazy >>= 1
            R_lazy >>= 1
            
        self._update_from_bottom(L)
        self._update_from_bottom(R - 1)
        
    # 区間取得 区間[L, R) (0-indexed)内の要素について
    # L番目から順にcombine_node_fを適用した値を返す。
    def fold(self, L, R):
        self._propagate_from_top(L)
        self._propagate_from_top(R - 1)
        
        L += self._size
        R += self._size
        value_L = self._indentity_e_node
        value_R = self._indentity_e_node
        while L < R:
            if L & 1:
                value_L = self._combine_node_f(value_L, self._reflect_lazy(L))
                L += 1
            if R & 1:
                R -= 1
                value_R = self._combine_node_f(value_R, self._reflect_lazy(R))
            L >>= 1
            R >>= 1
        return self._combine_node_f(value_L, value_R)
    
def combine_lazy(L, R):
    return R

def reflect(node, lazy):
    if lazy < 0:
        return node
    else:
        return lazy
    
M = 200005
def f(B, L, R):
    return R + L * M + B * M * M

N, Q = map(int, readline().split())
D = []
for i in range(Q):
    L, R, B = map(int, readline().split())
    D.append(f(B, L, R))
    
D.sort()    
T = LazySegmentTree(N, 10**9, -1, min, combine_lazy, reflect)
for v in D:
    R = v % M
    B, L = divmod(v//M, M)
    T.update(L - 1, R, B)

for v in D:
    R = v % M
    B, L = divmod(v//M, M)
    if T.fold(L - 1, R) != B:
        print(-1)
        exit()
ans = []
for i in range(N):
    ans.append(T.fold(i, i + 1))
    
print(*ans)
0