結果

問題 No.1675 Strange Minimum Query
ユーザー jamesjames
提出日時 2021-09-11 14:00:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,505 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 76,008 KB
最終ジャッジ日時 2023-09-05 00:49:16
合計ジャッジ時間 22,014 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 17 ms
8,324 KB
testcase_02 AC 17 ms
8,528 KB
testcase_03 AC 1,262 ms
49,544 KB
testcase_04 AC 1,907 ms
52,356 KB
testcase_05 AC 1,470 ms
27,396 KB
testcase_06 AC 1,493 ms
56,560 KB
testcase_07 TLE -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from operator import itemgetter

N,Q = map(int,input().split())
queries = [list(map(int,input().split())) for i in range(Q)]

queries.sort(key=itemgetter(2))

seg_el = 1 << ((N+1).bit_length()) # Segment-treeの台の要素数
SEG = [1]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment-treeの初期値で初期化

def getvalue(n, seg_el): # 1点の値を取得
    i = n + seg_el
    ans = 0

    ans = max(SEG[i],ans)
    i >>= 1 # 子ノードへ

    while i != 0:
        ans = max(SEG[i], ans)
        i >>= 1

    return ans

def updates(l, r, x): # 区間[l,r)のminを更新
    L = l + seg_el
    R = r + seg_el

    while L < R:
        if L & 1:
            SEG[L] = x
            L += 1

        if R & 1:
            SEG[R] = x
        L >>= 1
        R >>= 1

for l, r, x in queries:
    updates(l,r+1,x)

A = [getvalue(i,seg_el) for i in range(1,N+1)]

A_length = len(A)
sparse_table = [A]

for i in range(A_length.bit_length()-1):
    j = 1 << i
    B = []
    for k in range(len(sparse_table[-1])-j):
        B.append(min(sparse_table[-1][k], sparse_table[-1][k+j]))
    sparse_table.append(B)

def query(l,r): # [l,r)におけるminを求める
    i = (r-l).bit_length()-1 # 何番目のsparse_tableを見るか.

    return min(sparse_table[i][l], sparse_table[i][r-(1 << i)]) # (1<<i)個であれば[l,r)が埋まるから、minを求める

for l,r,x in queries:
    if query(l-1,r) != x:
        print(-1)
        exit()

print(*A)
0