結果

問題 No.1675 Strange Minimum Query
ユーザー gr1msl3ygr1msl3y
提出日時 2021-09-10 22:13:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,605 ms / 2,000 ms
コード長 2,680 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 125,508 KB
最終ジャッジ日時 2023-09-02 18:10:27
合計ジャッジ時間 33,568 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,184 KB
testcase_01 AC 76 ms
71,100 KB
testcase_02 AC 77 ms
70,984 KB
testcase_03 AC 807 ms
98,832 KB
testcase_04 AC 788 ms
102,348 KB
testcase_05 AC 324 ms
89,148 KB
testcase_06 AC 809 ms
101,780 KB
testcase_07 AC 1,003 ms
108,596 KB
testcase_08 AC 83 ms
75,472 KB
testcase_09 AC 144 ms
78,704 KB
testcase_10 AC 613 ms
109,552 KB
testcase_11 AC 361 ms
101,168 KB
testcase_12 AC 662 ms
111,136 KB
testcase_13 AC 640 ms
121,400 KB
testcase_14 AC 854 ms
125,508 KB
testcase_15 AC 708 ms
124,248 KB
testcase_16 AC 76 ms
70,964 KB
testcase_17 AC 473 ms
89,092 KB
testcase_18 AC 535 ms
90,716 KB
testcase_19 AC 680 ms
106,068 KB
testcase_20 AC 1,125 ms
115,124 KB
testcase_21 AC 974 ms
113,568 KB
testcase_22 AC 1,218 ms
118,716 KB
testcase_23 AC 1,053 ms
101,060 KB
testcase_24 AC 989 ms
104,340 KB
testcase_25 AC 799 ms
96,864 KB
testcase_26 AC 522 ms
95,700 KB
testcase_27 AC 942 ms
112,060 KB
testcase_28 AC 650 ms
104,656 KB
testcase_29 AC 540 ms
104,132 KB
testcase_30 AC 505 ms
93,972 KB
testcase_31 AC 1,268 ms
110,224 KB
testcase_32 AC 1,605 ms
124,608 KB
testcase_33 AC 1,532 ms
124,084 KB
testcase_34 AC 1,521 ms
124,628 KB
testcase_35 AC 1,440 ms
124,788 KB
testcase_36 AC 1,451 ms
124,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(Q)]
for i in range(Q):
    A[i][0] -= 1


INF = 2*10**9
opX = max
opY = max
UnitX = -INF
UnitY = -INF
act = max


class LazySegmentTree():
    def __init__(self, n, opX, opY, UnitX, UnitY, A=None):
        self.s = 2**((n-1).bit_length())
        self.size = 2*self.s
        self.node = [UnitX]*self.size
        self.lazy = [UnitY]*self.size
        if A:
            for i in range(n):
                self.node[self.s+i] = A[i]
            for i in range(self.s-1, -1, -1):
                self.node[i] = opX(self.node[2*i], self.node[2*i+1])

    def propagation(self, i):
        h = i.bit_length()-1
        for n in range(h, 0, -1):
            j = i >> n
            if self.lazy[j] != UnitY:
                self.node[j] = act(self.node[j], self.lazy[j])
                self.lazy[2*j] = opY(self.lazy[2*j], self.lazy[j])
                self.lazy[2*j+1] = opY(self.lazy[2*j+1], self.lazy[j])
                self.lazy[j] = UnitY

    def recalculate(self, i):
        while i > 1:
            i >>= 1
            x = act(self.node[2*i], self.lazy[2*i])
            y = act(self.node[2*i+1], self.lazy[2*i+1])
            self.node[i] = opX(x, y)

    def update_range(self, L, R, a):
        L += self.s
        R += self.s
        L0 = L//(L & -L)
        R0 = R//(R & -R)
        self.propagation(L0)
        self.propagation(R0)
        while L < R:
            if L & 1:
                self.lazy[L] = opY(self.lazy[L], a)
                L += 1
            if R & 1:
                R -= 1
                self.lazy[R] = opY(self.lazy[R], a)
            L >>= 1
            R >>= 1
        self.recalculate(L0)
        self.recalculate(R0)

    def get_range(self, L, R):
        vL, vR = UnitX, UnitX
        L += self.s
        R += self.s
        L0 = L//(L & -L)
        R0 = R//(R & -R)
        self.propagation(L0)
        self.propagation(R0)
        while L < R:
            if L & 1:
                vL = opX(vL, act(self.node[L], self.lazy[L]))
                L += 1
            if R & 1:
                R -= 1
                vR = opX(act(self.node[R], self.lazy[R]), vR)
            L >>= 1
            R >>= 1
        return opX(vL, vR)


state = LazySegmentTree(N, max, max, -INF, -INF)
for l, r, v in A:
    state.update_range(l, r, v)

seq = [state.get_range(i, i+1) for i in range(N)]
for i in range(N):
    if seq[i] == -INF:
        seq[i] = 1
opX = min
opY = min
UnitX = INF
UnitY = INF
act = min
solve = LazySegmentTree(N, min, min, INF, INF, seq)

for l, r, v in A:
    if solve.get_range(l, r) != v:
        print(-1)
        break
else:
    print(*seq)
0