結果
問題 | No.1675 Strange Minimum Query |
ユーザー | mkawa2 |
提出日時 | 2021-09-10 22:00:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 900 ms / 2,000 ms |
コード長 | 1,918 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 82,068 KB |
実行使用メモリ | 191,240 KB |
最終ジャッジ日時 | 2024-06-12 00:04:13 |
合計ジャッジ時間 | 21,170 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,992 KB |
testcase_01 | AC | 41 ms
52,608 KB |
testcase_02 | AC | 39 ms
52,992 KB |
testcase_03 | AC | 507 ms
129,412 KB |
testcase_04 | AC | 607 ms
137,536 KB |
testcase_05 | AC | 202 ms
104,864 KB |
testcase_06 | AC | 592 ms
139,136 KB |
testcase_07 | AC | 633 ms
151,356 KB |
testcase_08 | AC | 40 ms
54,012 KB |
testcase_09 | AC | 71 ms
73,088 KB |
testcase_10 | AC | 325 ms
135,452 KB |
testcase_11 | AC | 162 ms
110,832 KB |
testcase_12 | AC | 349 ms
142,180 KB |
testcase_13 | AC | 352 ms
184,484 KB |
testcase_14 | AC | 409 ms
190,172 KB |
testcase_15 | AC | 487 ms
191,240 KB |
testcase_16 | AC | 39 ms
53,120 KB |
testcase_17 | AC | 248 ms
97,188 KB |
testcase_18 | AC | 287 ms
103,096 KB |
testcase_19 | AC | 384 ms
133,588 KB |
testcase_20 | AC | 596 ms
151,988 KB |
testcase_21 | AC | 792 ms
154,912 KB |
testcase_22 | AC | 660 ms
169,332 KB |
testcase_23 | AC | 547 ms
133,224 KB |
testcase_24 | AC | 548 ms
138,568 KB |
testcase_25 | AC | 428 ms
113,684 KB |
testcase_26 | AC | 288 ms
106,884 KB |
testcase_27 | AC | 496 ms
151,936 KB |
testcase_28 | AC | 357 ms
124,308 KB |
testcase_29 | AC | 288 ms
124,708 KB |
testcase_30 | AC | 284 ms
107,448 KB |
testcase_31 | AC | 629 ms
145,620 KB |
testcase_32 | AC | 857 ms
190,916 KB |
testcase_33 | AC | 865 ms
188,764 KB |
testcase_34 | AC | 879 ms
188,872 KB |
testcase_35 | AC | 891 ms
181,628 KB |
testcase_36 | AC | 900 ms
182,300 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**20 md = 998244353 # md = 10**9+7 class SparseTableMin: def __init__(self, aa): w = len(aa) h = w.bit_length() table = [aa]+[[-1]*w for _ in range(h-1)] tablei1 = table[0] for i in range(1, h): tablei = table[i] for j in range(w-(1 << i)+1): rj = j+(1 << (i-1)) tablei[j] = min(tablei1[j], tablei1[rj]) tablei1 = tablei self.table = table # [l,r)の最小値 def min(self, l, r): i = (r-l).bit_length()-1 tablei = self.table[i] Lmin = tablei[l] Rmin = tablei[r-(1 << i)] if Lmin < Rmin: Rmin = Lmin return Rmin from heapq import * mx = 10**9 n, q = LI() aa = [mx]*n lrb = [] ltorb = [[] for _ in range(n+1)] rtob = [[] for _ in range(n+1)] for _ in range(q): l, r, b = LI() l -= 1 lrb.append((l, r, b)) ltorb[l].append((r, b)) rtob[r].append(b) hp = [] rem = [] aa = [mx]*n for i in range(n): for b in rtob[i]: heappush(rem, -b) while hp and rem and hp[0] == rem[0]: heappop(hp) heappop(rem) for r, b in ltorb[i]: heappush(hp, -b) if not hp: continue aa[i] = -hp[0] sp = SparseTableMin(aa) for l, r, b in lrb: if sp.min(l, r) != b: print(-1) exit() print(*aa)