結果
問題 | No.1675 Strange Minimum Query |
ユーザー | james |
提出日時 | 2021-09-11 14:03:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 871 ms / 2,000 ms |
コード長 | 1,490 bytes |
コンパイル時間 | 760 ms |
コンパイル使用メモリ | 87,124 KB |
実行使用メモリ | 259,608 KB |
最終ジャッジ日時 | 2023-09-05 00:53:09 |
合計ジャッジ時間 | 23,063 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,560 KB |
testcase_01 | AC | 77 ms
71,396 KB |
testcase_02 | AC | 75 ms
71,328 KB |
testcase_03 | AC | 513 ms
105,380 KB |
testcase_04 | AC | 535 ms
148,256 KB |
testcase_05 | AC | 266 ms
195,024 KB |
testcase_06 | AC | 627 ms
117,064 KB |
testcase_07 | AC | 647 ms
138,380 KB |
testcase_08 | AC | 82 ms
75,740 KB |
testcase_09 | AC | 107 ms
77,956 KB |
testcase_10 | AC | 462 ms
183,592 KB |
testcase_11 | AC | 298 ms
183,928 KB |
testcase_12 | AC | 505 ms
244,652 KB |
testcase_13 | AC | 532 ms
259,148 KB |
testcase_14 | AC | 518 ms
259,100 KB |
testcase_15 | AC | 527 ms
225,904 KB |
testcase_16 | AC | 76 ms
71,488 KB |
testcase_17 | AC | 260 ms
117,404 KB |
testcase_18 | AC | 284 ms
112,960 KB |
testcase_19 | AC | 435 ms
259,608 KB |
testcase_20 | AC | 546 ms
190,856 KB |
testcase_21 | AC | 553 ms
259,532 KB |
testcase_22 | AC | 663 ms
258,852 KB |
testcase_23 | AC | 482 ms
150,600 KB |
testcase_24 | AC | 502 ms
172,952 KB |
testcase_25 | AC | 371 ms
135,720 KB |
testcase_26 | AC | 312 ms
126,932 KB |
testcase_27 | AC | 559 ms
259,052 KB |
testcase_28 | AC | 395 ms
217,160 KB |
testcase_29 | AC | 397 ms
258,212 KB |
testcase_30 | AC | 314 ms
141,584 KB |
testcase_31 | AC | 558 ms
156,660 KB |
testcase_32 | AC | 779 ms
258,916 KB |
testcase_33 | AC | 770 ms
259,508 KB |
testcase_34 | AC | 788 ms
259,360 KB |
testcase_35 | AC | 844 ms
253,224 KB |
testcase_36 | AC | 871 ms
259,272 KB |
ソースコード
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): # 一点の値を取得 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)