結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 timitimi
提出日時 2021-09-13 13:17:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,777 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 133,768 KB
最終ジャッジ日時 2023-09-07 18:53:42
合計ジャッジ時間 43,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
70,916 KB
testcase_01 AC 67 ms
71,052 KB
testcase_02 AC 68 ms
71,176 KB
testcase_03 AC 1,064 ms
101,020 KB
testcase_04 AC 1,015 ms
107,288 KB
testcase_05 AC 214 ms
83,804 KB
testcase_06 AC 1,230 ms
104,292 KB
testcase_07 AC 1,337 ms
108,212 KB
testcase_08 AC 79 ms
76,528 KB
testcase_09 AC 139 ms
78,344 KB
testcase_10 AC 823 ms
113,740 KB
testcase_11 AC 427 ms
100,060 KB
testcase_12 AC 894 ms
114,772 KB
testcase_13 AC 1,031 ms
127,800 KB
testcase_14 AC 1,401 ms
133,768 KB
testcase_15 AC 1,235 ms
133,156 KB
testcase_16 AC 66 ms
71,024 KB
testcase_17 AC 501 ms
88,896 KB
testcase_18 AC 610 ms
90,744 KB
testcase_19 AC 858 ms
109,440 KB
testcase_20 AC 1,529 ms
116,080 KB
testcase_21 AC 1,411 ms
117,412 KB
testcase_22 AC 1,697 ms
126,812 KB
testcase_23 AC 1,333 ms
103,876 KB
testcase_24 AC 1,270 ms
110,320 KB
testcase_25 AC 964 ms
97,228 KB
testcase_26 AC 592 ms
94,800 KB
testcase_27 AC 1,343 ms
117,280 KB
testcase_28 AC 762 ms
105,140 KB
testcase_29 AC 687 ms
105,556 KB
testcase_30 AC 619 ms
94,988 KB
testcase_31 AC 1,705 ms
116,544 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 1,940 ms
131,488 KB
testcase_36 AC 1,992 ms
131,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  N,Q=map(int, input().split())
  INF =10**9
  LV = (N-1).bit_length()
  N0 = 2**LV
  data = [INF]*(2*N0)
  lazy = [None]*(2*N0)

  # 伝搬対象の区間を求める
  def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

  # 遅延伝搬処理
  def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

  # 区間[l, r)をxで更新
  def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

  # 区間[l, r)内の最小値を求める(最大値の時はminをmaxに変えよう)
  def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

  B=[list(map(int, input().split())) for i in range(Q)]
  B=sorted(B,key=lambda x:x[2])
  for l,r,b in B:
    update(l-1,r,b)  
  for l,r,b in B:
    if b!=query(l-1,r):
      print(-1)
      exit()
    
  A=[]
  for i in range(N):
    A.append(query(i,i+1))
  print(*A)

if __name__ == '__main__':
    main()
0