結果

問題 No.1675 Strange Minimum Query
ユーザー ansainansain
提出日時 2021-09-10 21:55:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,538 ms / 2,000 ms
コード長 5,911 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 123,664 KB
最終ジャッジ日時 2024-06-11 23:45:11
合計ジャッジ時間 31,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,912 KB
testcase_01 AC 42 ms
55,040 KB
testcase_02 AC 43 ms
55,296 KB
testcase_03 AC 903 ms
100,800 KB
testcase_04 AC 710 ms
95,192 KB
testcase_05 AC 171 ms
83,204 KB
testcase_06 AC 980 ms
99,584 KB
testcase_07 AC 1,023 ms
111,616 KB
testcase_08 AC 57 ms
65,520 KB
testcase_09 AC 127 ms
78,024 KB
testcase_10 AC 595 ms
96,580 KB
testcase_11 AC 305 ms
88,620 KB
testcase_12 AC 646 ms
98,412 KB
testcase_13 AC 705 ms
112,972 KB
testcase_14 AC 989 ms
123,664 KB
testcase_15 AC 930 ms
115,380 KB
testcase_16 AC 43 ms
55,168 KB
testcase_17 AC 406 ms
84,920 KB
testcase_18 AC 494 ms
86,836 KB
testcase_19 AC 535 ms
94,292 KB
testcase_20 AC 1,012 ms
103,704 KB
testcase_21 AC 1,013 ms
100,928 KB
testcase_22 AC 1,081 ms
106,252 KB
testcase_23 AC 872 ms
97,324 KB
testcase_24 AC 836 ms
100,132 KB
testcase_25 AC 666 ms
94,596 KB
testcase_26 AC 461 ms
87,468 KB
testcase_27 AC 855 ms
104,192 KB
testcase_28 AC 508 ms
91,668 KB
testcase_29 AC 424 ms
91,428 KB
testcase_30 AC 428 ms
87,436 KB
testcase_31 AC 1,281 ms
102,256 KB
testcase_32 AC 1,446 ms
112,304 KB
testcase_33 AC 1,538 ms
111,688 KB
testcase_34 AC 1,466 ms
112,472 KB
testcase_35 AC 1,336 ms
114,196 KB
testcase_36 AC 1,299 ms
114,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict, Counter, deque
from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate
import operator
from math import sqrt, gcd, factorial
#from math import isqrt, prod, comb  #python3.8用(notpypy)
#from bisect import bisect_left, bisect_right
#from functools import lru_cache, reduce
#from heapq import heappush, heappop, heapify, heappushpop, heapreplace
#import numpy as np
#import networkx as nx
#from networkx.utils import UnionFind
#from numba import njit, b1, i1, i4, i8, f8
#numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError, maximum_bipartite_matching, maximum_flow, minimum_spanning_tree
def input(): return sys.stdin.readline().rstrip()
def divceil(n, k): return 1+(n-1)//k  # n/kの切り上げを返す
def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no)

#ライブラリ参照https://atcoder.jp/contests/practice2/submissions/20978786
class LazySegmentTree2:
 
    __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"]
 
    def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator):
        self.me = monoid_identity
        self.oe = operator_identity
        self.fmm = func_monoid_monoid
        self.fmo = func_monoid_operator
        self.foo = func_operator_operator
 
        self.n = len(monoid_data)
        self.data = monoid_data * 2
        for i in range(self.n-1, 0, -1):
            self.data[i] = self.fmm(self.data[2*i], self.data[2*i+1])
        self.lazy = [self.oe] * (self.n * 2)
        
 
    def replace(self, index, value):
        index += self.n
 
        # propagation
        for shift in range(index.bit_length()-1, 0, -1):
            i = index >> shift
            self.lazy[2*i]   = self.foo(self.lazy[2*i],   self.lazy[i])
            self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i])
            self.data[i] = self.fmo(self.data[i], self.lazy[i])
            self.lazy[i] = self.oe
 
        # update
        self.data[index] = value
        self.lazy[index] = self.oe
 
        # recalculation
        i = index
        while i > 1:
            i //= 2
            self.data[i] = self.fmm( self.fmo(self.data[2*i], self.lazy[2*i]), self.fmo(self.data[2*i+1], self.lazy[2*i+1]) )
            self.lazy[i] = self.oe
 
 
    def effect(self, l, r, operator):
        l += self.n
        r += self.n
        
        # preparing indices
        indices = []
        l0 = (l // (l & -l))     // 2
        r0 = (r // (r & -r) - 1) // 2
        while r0 > l0:
            indices.append(r0)
            r0 //= 2
        while l0 > r0:
            indices.append(l0)
            l0 //= 2
        while l0 and l0 != r0:
            indices.append(r0)
            r0 //= 2
            if l0 == r0:
                break
            indices.append(l0)
            l0 //= 2
        while r0:
            indices.append(r0)
            r0 //= 2
 
        # propagation
        for i in reversed(indices):
            self.lazy[2*i]   = self.foo(self.lazy[2*i],   self.lazy[i])
            self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i])
            self.data[i] = self.fmo(self.data[i], self.lazy[i])
            self.lazy[i] = self.oe
 
        # effect
        while l < r:
            if l % 2:
                self.lazy[l] = self.foo(self.lazy[l], operator)
                l += 1
            if r % 2:
                r -= 1
                self.lazy[r] = self.foo(self.lazy[r], operator)
            l //= 2
            r //= 2
 
        # recalculation
        for i in indices:
            self.data[i] = self.fmm( self.fmo(self.data[2*i], self.lazy[2*i]), self.fmo(self.data[2*i+1], self.lazy[2*i+1]) )
            self.lazy[i] = self.oe
            
        
    def folded(self, l, r):
        l += self.n
        r += self.n
 
        # preparing indices
        indices = []
        l0 = (l // (l & -l))     // 2
        r0 = (r // (r & -r) - 1) // 2
        while r0 > l0:
            indices.append(r0)
            r0 //= 2
        while l0 > r0:
            indices.append(l0)
            l0 //= 2
        while l0 and l0 != r0:
            indices.append(r0)
            r0 //= 2
            if l0 == r0:
                break
            indices.append(l0)
            l0 //= 2
        while r0:
            indices.append(r0)
            r0 //= 2
        
        # propagation
        for i in reversed(indices):
            self.lazy[2*i]   = self.foo(self.lazy[2*i],   self.lazy[i])
            self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i])
            self.data[i] = self.fmo(self.data[i], self.lazy[i])
            self.lazy[i] = self.oe
 
        # fold
        left_folded = self.me
        right_folded = self.me
        while l < r:
            if l % 2:
                left_folded = self.fmm(left_folded, self.fmo(self.data[l], self.lazy[l]))
                l += 1
            if r % 2:
                r -= 1
                right_folded = self.fmm(self.fmo(self.data[r], self.lazy[r]), right_folded)
            l //= 2
            r //= 2
        return self.fmm(left_folded, right_folded)

def main():
    mod = 10**9+7
    mod2 = 998244353
    n,q=map(int, input().split())
    lrb=[list(map(int, input().split())) for i in range(q)]
    lrb.sort(key=lambda x:x[2])
    seg=LazySegmentTree2([10**9]*n,10**9,-1,min,lambda x,y: x if y==-1 else y,lambda x,y: x if y==-1 else y)
    for l,r,b in lrb:
        seg.effect(l-1,r,b)
    for l,r,b in lrb:
        if seg.folded(l-1,r)!=b:
            print(-1)
            return
    print(*[seg.folded(i,i+1) for i in range(n)])



if __name__ == '__main__':
    main()
0