結果
問題 | No.1675 Strange Minimum Query |
ユーザー | titia |
提出日時 | 2021-09-10 22:27:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 920 ms / 2,000 ms |
コード長 | 1,490 bytes |
コンパイル時間 | 1,439 ms |
コンパイル使用メモリ | 87,068 KB |
実行使用メモリ | 259,260 KB |
最終ジャッジ日時 | 2023-09-02 18:41:52 |
合計ジャッジ時間 | 24,833 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
71,228 KB |
testcase_01 | AC | 80 ms
71,408 KB |
testcase_02 | AC | 80 ms
71,480 KB |
testcase_03 | AC | 527 ms
105,208 KB |
testcase_04 | AC | 531 ms
148,068 KB |
testcase_05 | AC | 264 ms
194,712 KB |
testcase_06 | AC | 638 ms
116,980 KB |
testcase_07 | AC | 650 ms
138,416 KB |
testcase_08 | AC | 84 ms
75,628 KB |
testcase_09 | AC | 114 ms
77,660 KB |
testcase_10 | AC | 459 ms
183,592 KB |
testcase_11 | AC | 292 ms
183,548 KB |
testcase_12 | AC | 539 ms
242,656 KB |
testcase_13 | AC | 920 ms
258,656 KB |
testcase_14 | AC | 510 ms
258,960 KB |
testcase_15 | AC | 519 ms
225,596 KB |
testcase_16 | AC | 81 ms
71,248 KB |
testcase_17 | AC | 257 ms
117,020 KB |
testcase_18 | AC | 290 ms
112,792 KB |
testcase_19 | AC | 435 ms
259,100 KB |
testcase_20 | AC | 565 ms
190,612 KB |
testcase_21 | AC | 559 ms
259,100 KB |
testcase_22 | AC | 661 ms
258,868 KB |
testcase_23 | AC | 487 ms
150,444 KB |
testcase_24 | AC | 502 ms
172,536 KB |
testcase_25 | AC | 371 ms
135,140 KB |
testcase_26 | AC | 314 ms
126,536 KB |
testcase_27 | AC | 562 ms
258,748 KB |
testcase_28 | AC | 390 ms
217,120 KB |
testcase_29 | AC | 400 ms
257,880 KB |
testcase_30 | AC | 317 ms
141,384 KB |
testcase_31 | AC | 585 ms
156,272 KB |
testcase_32 | AC | 770 ms
258,424 KB |
testcase_33 | AC | 790 ms
259,260 KB |
testcase_34 | AC | 768 ms
259,028 KB |
testcase_35 | AC | 850 ms
252,748 KB |
testcase_36 | AC | 888 ms
258,744 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)