結果

問題 No.1675 Strange Minimum Query
ユーザー tcltktcltk
提出日時 2021-10-16 18:02:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,942 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 148,612 KB
最終ジャッジ日時 2023-10-17 22:14:47
合計ジャッジ時間 28,545 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
85,852 KB
testcase_01 AC 122 ms
85,848 KB
testcase_02 AC 125 ms
85,852 KB
testcase_03 AC 763 ms
114,388 KB
testcase_04 AC 883 ms
113,556 KB
testcase_05 AC 189 ms
97,840 KB
testcase_06 AC 894 ms
118,728 KB
testcase_07 AC 1,003 ms
123,584 KB
testcase_08 AC 130 ms
85,868 KB
testcase_09 AC 150 ms
88,708 KB
testcase_10 AC 440 ms
114,004 KB
testcase_11 AC 224 ms
105,964 KB
testcase_12 AC 473 ms
115,504 KB
testcase_13 AC 631 ms
147,396 KB
testcase_14 AC 407 ms
132,456 KB
testcase_15 AC 900 ms
148,612 KB
testcase_16 AC 128 ms
85,868 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """5 3
# 1 3 1
# 3 5 3
# 4 5 4

# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

class SegTree_Update_QRMin:
    def __init__(self, a) -> None:
        n = len(a)
        self.n0 = 1 << (n-1).bit_length()
        self.data = ([INF] * self.n0) + a + ([INF] * (self.n0-n))
        for i in reversed(range(1, self.n0)):
            self.data[i] = min(self.data[i*2], self.data[i*2+1])
    def query_rmin(self, l, r):
        l += self.n0
        r += self.n0
        s = INF
        while l < r:
            if l & 1:
                s = min(s, self.data[l])
                l += 1
            if r & 1:
                s = min(s, self.data[r-1])
                r -= 1
            l >>= 1
            r >>= 1
        return s
    def update(self, i, x):
        i += self.n0
        self.data[i] = x
        while i > 0:
            i >>= 1
            self.data[i] = min(self.data[i*2], self.data[i*2+1])
    def get_value(self, i) -> int:
        return self.data[i+self.n0]

def solve(N, Q, Query):
    Query.sort()
    hq = []
    result = [10**9] * N
    k = 0
    for i in range(N):
        while k < Q and Query[k][0] == i:
            l, r, a = Query[k]
            k += 1
            heapq.heappush(hq, (r, l, a))
        if hq:
            r, l, a = heapq.heappop(hq)
            if r < i:
                return [-1]
            result[i] = a
    
    seg_tree = SegTree_Update_QRMin(result)
    for l, r, a in Query:
        if seg_tree.query_rmin(l, r+1) != a:
            return [-1]
    return result


N, Q = map(int, input().split())
Query = []
for _ in range(Q):
    l, r, a = map(int, input().split())
    Query.append((l-1, r-1, a))

print(*solve(N, Q, Query))
0