結果

問題 No.1675 Strange Minimum Query
ユーザー jamesjames
提出日時 2021-09-11 14:01:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,505 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 259,920 KB
最終ジャッジ日時 2023-09-05 00:50:41
合計ジャッジ時間 18,482 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 72 ms
71,564 KB
testcase_02 AC 69 ms
71,520 KB
testcase_03 AC 489 ms
105,584 KB
testcase_04 AC 495 ms
148,428 KB
testcase_05 AC 250 ms
198,304 KB
testcase_06 AC 613 ms
117,048 KB
testcase_07 AC 606 ms
135,000 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 70 ms
71,680 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 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