結果

問題 No.1675 Strange Minimum Query
ユーザー tktk_snsntktk_snsn
提出日時 2021-09-10 22:04:42
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 945 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 11,116 KB
実行使用メモリ 83,536 KB
最終ジャッジ日時 2023-09-02 17:47:24
合計ジャッジ時間 21,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,792 KB
testcase_01 AC 20 ms
8,660 KB
testcase_02 AC 20 ms
8,768 KB
testcase_03 AC 471 ms
66,468 KB
testcase_04 AC 441 ms
58,104 KB
testcase_05 AC 118 ms
17,184 KB
testcase_06 AC 577 ms
79,188 KB
testcase_07 AC 605 ms
81,440 KB
testcase_08 AC 19 ms
8,676 KB
testcase_09 AC 23 ms
9,128 KB
testcase_10 AC 494 ms
37,864 KB
testcase_11 AC 151 ms
16,612 KB
testcase_12 AC 550 ms
41,240 KB
testcase_13 AC 584 ms
39,988 KB
testcase_14 AC 939 ms
83,536 KB
testcase_15 AC 945 ms
83,516 KB
testcase_16 AC 19 ms
8,660 KB
testcase_17 AC 141 ms
14,632 KB
testcase_18 AC 180 ms
16,784 KB
testcase_19 AC 330 ms
20,608 KB
testcase_20 AC 483 ms
31,312 KB
testcase_21 AC 489 ms
29,404 KB
testcase_22 AC 591 ms
35,136 KB
testcase_23 AC 393 ms
29,420 KB
testcase_24 AC 415 ms
27,940 KB
testcase_25 AC 283 ms
22,824 KB
testcase_26 AC 194 ms
16,228 KB
testcase_27 AC 465 ms
27,532 KB
testcase_28 AC 283 ms
19,464 KB
testcase_29 AC 277 ms
17,632 KB
testcase_30 AC 200 ms
16,328 KB
testcase_31 AC 502 ms
35,416 KB
testcase_32 AC 733 ms
43,216 KB
testcase_33 AC 721 ms
43,244 KB
testcase_34 AC 741 ms
43,172 KB
testcase_35 AC 807 ms
44,996 KB
testcase_36 AC 812 ms
45,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)

    def find(self, x):
        stack = []
        while self.root[x] > 0:
            stack.append(x)
            x = self.root[x]
        for i in stack:
            self.root[i] = x
        return x

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if x < y:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x
        return True

    def size(self, x):
        return -self.root[self.find(x)]


def main():
    d = defaultdict(list)
    val = set()
    N, Q = map(int, input().split())
    for _ in range(Q):
        L, R, B = map(int, input().split())
        val.add(B)
        d[B].append((L, R))

    ans = [-1] * N
    uf = UF_tree(N)
    for v in sorted(val, reverse=True):
        for l, r in d[v]:
            l -= 1
            l = uf.find(l)
            if l < r:
                if ans[l] < 0:
                    ans[l] = v
            else:
                print(-1)
                return
        for l, r in d[v]:
            l -= 1
            l = uf.find(l)
            while l < r:
                uf.unite(l, l+1)
                l = uf.find(l)

    for i in range(N):
        if ans[i] < 0:
            ans[i] = 10 ** 9
    print(*ans)
    return


main()
0