結果
問題 | No.1675 Strange Minimum Query |
ユーザー | gr1msl3y |
提出日時 | 2021-09-10 22:13:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,553 ms / 2,000 ms |
コード長 | 2,680 bytes |
コンパイル時間 | 330 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 124,148 KB |
最終ジャッジ日時 | 2024-06-12 00:37:40 |
合計ジャッジ時間 | 30,849 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,992 KB |
testcase_01 | AC | 40 ms
52,864 KB |
testcase_02 | AC | 39 ms
53,120 KB |
testcase_03 | AC | 727 ms
97,504 KB |
testcase_04 | AC | 739 ms
101,340 KB |
testcase_05 | AC | 287 ms
87,880 KB |
testcase_06 | AC | 753 ms
100,724 KB |
testcase_07 | AC | 940 ms
107,580 KB |
testcase_08 | AC | 47 ms
60,432 KB |
testcase_09 | AC | 110 ms
77,440 KB |
testcase_10 | AC | 570 ms
107,968 KB |
testcase_11 | AC | 323 ms
99,764 KB |
testcase_12 | AC | 613 ms
109,752 KB |
testcase_13 | AC | 585 ms
120,624 KB |
testcase_14 | AC | 825 ms
123,936 KB |
testcase_15 | AC | 679 ms
124,148 KB |
testcase_16 | AC | 39 ms
52,836 KB |
testcase_17 | AC | 430 ms
87,532 KB |
testcase_18 | AC | 495 ms
89,100 KB |
testcase_19 | AC | 661 ms
104,952 KB |
testcase_20 | AC | 1,080 ms
113,708 KB |
testcase_21 | AC | 884 ms
112,020 KB |
testcase_22 | AC | 1,149 ms
116,964 KB |
testcase_23 | AC | 928 ms
99,484 KB |
testcase_24 | AC | 910 ms
103,244 KB |
testcase_25 | AC | 732 ms
94,032 KB |
testcase_26 | AC | 479 ms
93,452 KB |
testcase_27 | AC | 903 ms
110,984 KB |
testcase_28 | AC | 609 ms
104,344 KB |
testcase_29 | AC | 514 ms
102,636 KB |
testcase_30 | AC | 463 ms
93,540 KB |
testcase_31 | AC | 1,184 ms
108,072 KB |
testcase_32 | AC | 1,553 ms
122,420 KB |
testcase_33 | AC | 1,476 ms
123,096 KB |
testcase_34 | AC | 1,456 ms
122,960 KB |
testcase_35 | AC | 1,346 ms
123,920 KB |
testcase_36 | AC | 1,366 ms
123,596 KB |
ソースコード
N, Q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(Q)] for i in range(Q): A[i][0] -= 1 INF = 2*10**9 opX = max opY = max UnitX = -INF UnitY = -INF act = max class LazySegmentTree(): def __init__(self, n, opX, opY, UnitX, UnitY, A=None): self.s = 2**((n-1).bit_length()) self.size = 2*self.s self.node = [UnitX]*self.size self.lazy = [UnitY]*self.size if A: for i in range(n): self.node[self.s+i] = A[i] for i in range(self.s-1, -1, -1): self.node[i] = opX(self.node[2*i], self.node[2*i+1]) def propagation(self, i): h = i.bit_length()-1 for n in range(h, 0, -1): j = i >> n if self.lazy[j] != UnitY: self.node[j] = act(self.node[j], self.lazy[j]) self.lazy[2*j] = opY(self.lazy[2*j], self.lazy[j]) self.lazy[2*j+1] = opY(self.lazy[2*j+1], self.lazy[j]) self.lazy[j] = UnitY def recalculate(self, i): while i > 1: i >>= 1 x = act(self.node[2*i], self.lazy[2*i]) y = act(self.node[2*i+1], self.lazy[2*i+1]) self.node[i] = opX(x, y) def update_range(self, L, R, a): L += self.s R += self.s L0 = L//(L & -L) R0 = R//(R & -R) self.propagation(L0) self.propagation(R0) while L < R: if L & 1: self.lazy[L] = opY(self.lazy[L], a) L += 1 if R & 1: R -= 1 self.lazy[R] = opY(self.lazy[R], a) L >>= 1 R >>= 1 self.recalculate(L0) self.recalculate(R0) def get_range(self, L, R): vL, vR = UnitX, UnitX L += self.s R += self.s L0 = L//(L & -L) R0 = R//(R & -R) self.propagation(L0) self.propagation(R0) while L < R: if L & 1: vL = opX(vL, act(self.node[L], self.lazy[L])) L += 1 if R & 1: R -= 1 vR = opX(act(self.node[R], self.lazy[R]), vR) L >>= 1 R >>= 1 return opX(vL, vR) state = LazySegmentTree(N, max, max, -INF, -INF) for l, r, v in A: state.update_range(l, r, v) seq = [state.get_range(i, i+1) for i in range(N)] for i in range(N): if seq[i] == -INF: seq[i] = 1 opX = min opY = min UnitX = INF UnitY = INF act = min solve = LazySegmentTree(N, min, min, INF, INF, seq) for l, r, v in A: if solve.get_range(l, r) != v: print(-1) break else: print(*seq)