結果

問題 No.1675 Strange Minimum Query
ユーザー ygd.ygd.
提出日時 2021-09-12 10:17:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,372 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 224,948 KB
最終ジャッジ日時 2023-09-06 03:40:13
合計ジャッジ時間 18,614 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,492 KB
testcase_01 AC 88 ms
71,580 KB
testcase_02 AC 90 ms
71,592 KB
testcase_03 AC 458 ms
135,252 KB
testcase_04 AC 432 ms
135,956 KB
testcase_05 AC 166 ms
101,988 KB
testcase_06 AC 504 ms
144,740 KB
testcase_07 AC 567 ms
154,916 KB
testcase_08 AC 90 ms
71,696 KB
testcase_09 AC 115 ms
77,536 KB
testcase_10 AC 373 ms
134,680 KB
testcase_11 AC 205 ms
109,064 KB
testcase_12 AC 386 ms
142,652 KB
testcase_13 AC 547 ms
171,448 KB
testcase_14 AC 484 ms
187,756 KB
testcase_15 AC 667 ms
224,948 KB
testcase_16 AC 92 ms
71,596 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 #

import sys
input = sys.stdin.readline
from collections import defaultdict 
from heapq import heapify, heappop, heappush, nlargest

#和のセグ木にするときは以下の関数を定義する必要あり。
def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def main():
    N,Q = map(int,input().split()); INF = pow(10,9)
    L = defaultdict(list)
    R = defaultdict(list)
    comp = set([])
    query = []
    PQ = []
    for i in range(Q):
        l,r,b = map(int,input().split())
        l -= 1; r -= 1 #0-index
        L[l].append((b,i))
        R[r].append((b,i))
        comp.add(b)
        query.append((l,r,b))

    ans = [INF]*N
    i = 0
    PQ = []
    while i < N:
        for b,idx in L[i]:
            heappush(PQ,(-b,idx)) #-Minとクエリ番号
        if PQ:
            b,idx = heappop(PQ)
            b *= -1
            if query[idx][1] < i: #この制約を満たせていない
                print(-1);exit()
            ans[i] = b
        i += 1
    #十分条件をチェック
    Tree = SegmentTree(ans,min,INF)
    for l,r,b in query:
        if Tree.sum(l,r+1) == b: continue
        else:
            print(-1);break
    else:
        print(*ans)

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