結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 tamatotamato
提出日時 2021-09-10 21:39:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 2,131 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 87,484 KB
実行使用メモリ 192,348 KB
最終ジャッジ日時 2023-09-02 16:23:01
合計ジャッジ時間 21,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,696 KB
testcase_01 AC 80 ms
71,692 KB
testcase_02 AC 81 ms
71,644 KB
testcase_03 AC 517 ms
131,872 KB
testcase_04 AC 577 ms
134,488 KB
testcase_05 AC 200 ms
102,188 KB
testcase_06 AC 565 ms
140,492 KB
testcase_07 AC 601 ms
151,908 KB
testcase_08 AC 87 ms
76,276 KB
testcase_09 AC 114 ms
77,948 KB
testcase_10 AC 456 ms
131,240 KB
testcase_11 AC 203 ms
108,868 KB
testcase_12 AC 484 ms
138,112 KB
testcase_13 AC 327 ms
159,364 KB
testcase_14 AC 462 ms
192,348 KB
testcase_15 AC 528 ms
187,720 KB
testcase_16 AC 78 ms
71,472 KB
testcase_17 AC 243 ms
95,536 KB
testcase_18 AC 268 ms
99,764 KB
testcase_19 AC 331 ms
125,976 KB
testcase_20 AC 471 ms
135,764 KB
testcase_21 AC 489 ms
141,484 KB
testcase_22 AC 539 ms
152,932 KB
testcase_23 AC 436 ms
119,664 KB
testcase_24 AC 434 ms
126,864 KB
testcase_25 AC 334 ms
106,944 KB
testcase_26 AC 263 ms
103,544 KB
testcase_27 AC 435 ms
141,152 KB
testcase_28 AC 329 ms
118,100 KB
testcase_29 AC 273 ms
119,568 KB
testcase_30 AC 262 ms
104,164 KB
testcase_31 AC 507 ms
129,628 KB
testcase_32 AC 701 ms
165,784 KB
testcase_33 AC 677 ms
165,892 KB
testcase_34 AC 695 ms
166,356 KB
testcase_35 AC 704 ms
162,220 KB
testcase_36 AC 735 ms
162,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from heapq import heappush, heappop
    input = sys.stdin.buffer.readline

    # min
    def STfunc(a, b):
        if a < b:
            return a
        else:
            return b

    # クエリは0-indexedで[l, r)
    class SparseTable():
        def __init__(self, A):
            # A: 処理したい数列
            self.N = len(A)
            self.K = self.N.bit_length() - 1
            self.table = [0] * (self.N * (self.K + 1))
            for i, a in enumerate(A):
                self.table[i] = a
            for k in range(1, self.K + 1):
                for i in range(self.N):
                    j = i + (1 << (k - 1))
                    if j <= self.N - 1:
                        self.table[i + k * self.N] = STfunc(self.table[i + (k - 1) * self.N],
                                                            self.table[j + (k - 1) * self.N])

        def query(self, l, r):
            # [l, r)の最小値を求める
            k = (r - l).bit_length() - 1
            return STfunc(self.table[l + k * self.N], self.table[r - (1 << k) + k * self.N])

    N, Q = map(int, input().split())
    pq = []
    imos = [[] for _ in range(N+1)]
    query = []
    for _ in range(Q):
        l, r, b = map(int, input().split())
        query.append((l, r, b))
        imos[l-1].append(b)
        imos[r].append(-b)
    ans = [10 ** 9] * N
    cnt = {}
    for i in range(N):
        for b in imos[i]:
            if b > 0:
                heappush(pq, -b)
                if b not in cnt:
                    cnt[b] = 0
                cnt[b] += 1
            else:
                cnt[-b] -= 1
        a = -1
        while pq:
            aa = -pq[0]
            if cnt[aa] == 0:
                heappop(pq)
            else:
                a = aa
                break
        if a != -1:
            ans[i] = a

    ok = 1
    ST = SparseTable(ans)
    for l, r, b in query:
        if ST.query(l-1, r) != b:
            ok = 0
            break
    if ok:
        print(*ans)
    else:
        print(-1)


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