結果

問題 No.1675 Strange Minimum Query
ユーザー titiatitia
提出日時 2021-09-10 22:22:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,490 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 259,396 KB
最終ジャッジ日時 2023-09-02 18:28:45
合計ジャッジ時間 22,521 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,220 KB
testcase_01 AC 78 ms
71,308 KB
testcase_02 AC 78 ms
71,292 KB
testcase_03 AC 561 ms
104,912 KB
testcase_04 AC 519 ms
148,036 KB
testcase_05 AC 254 ms
194,652 KB
testcase_06 AC 628 ms
116,708 KB
testcase_07 AC 642 ms
138,436 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 514 ms
258,636 KB
testcase_14 AC 496 ms
259,060 KB
testcase_15 AC 502 ms
225,328 KB
testcase_16 AC 79 ms
71,232 KB
testcase_17 AC 254 ms
116,896 KB
testcase_18 AC 286 ms
112,556 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 648 ms
258,572 KB
testcase_23 AC 464 ms
150,256 KB
testcase_24 AC 479 ms
172,520 KB
testcase_25 AC 367 ms
135,316 KB
testcase_26 WA -
testcase_27 AC 552 ms
258,688 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 557 ms
156,248 KB
testcase_32 AC 759 ms
258,448 KB
testcase_33 AC 750 ms
259,396 KB
testcase_34 AC 761 ms
258,816 KB
testcase_35 AC 823 ms
252,904 KB
testcase_36 AC 846 ms
258,696 KB
権限があれば一括ダウンロードができます

ソースコード

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=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def getvalue(n,seg_el): # 一点の値を取得
    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:
            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)]

#print(*A)

LEN = len(A)
Sparse_table = [A]

for i in range(LEN.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