結果
問題 | No.2223 Merged Med |
ユーザー | stoq |
提出日時 | 2023-02-16 06:57:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,932 ms / 7,000 ms |
コード長 | 2,342 bytes |
コンパイル時間 | 347 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 290,940 KB |
最終ジャッジ日時 | 2024-07-19 11:54:11 |
合計ジャッジ時間 | 78,348 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
89,152 KB |
testcase_01 | AC | 77 ms
88,784 KB |
testcase_02 | AC | 88 ms
89,344 KB |
testcase_03 | AC | 81 ms
88,856 KB |
testcase_04 | AC | 86 ms
89,004 KB |
testcase_05 | AC | 115 ms
100,172 KB |
testcase_06 | AC | 78 ms
89,208 KB |
testcase_07 | AC | 117 ms
99,984 KB |
testcase_08 | AC | 115 ms
100,068 KB |
testcase_09 | AC | 112 ms
100,268 KB |
testcase_10 | AC | 115 ms
100,256 KB |
testcase_11 | AC | 80 ms
89,252 KB |
testcase_12 | AC | 107 ms
99,896 KB |
testcase_13 | AC | 1,944 ms
261,572 KB |
testcase_14 | AC | 1,136 ms
191,700 KB |
testcase_15 | AC | 3,136 ms
284,016 KB |
testcase_16 | AC | 4,182 ms
290,940 KB |
testcase_17 | AC | 2,193 ms
276,184 KB |
testcase_18 | AC | 1,194 ms
189,268 KB |
testcase_19 | AC | 1,746 ms
250,892 KB |
testcase_20 | AC | 4,713 ms
284,252 KB |
testcase_21 | AC | 4,899 ms
284,060 KB |
testcase_22 | AC | 4,772 ms
286,744 KB |
testcase_23 | AC | 4,758 ms
287,332 KB |
testcase_24 | AC | 4,863 ms
285,212 KB |
testcase_25 | AC | 4,766 ms
286,124 KB |
testcase_26 | AC | 4,932 ms
282,152 KB |
testcase_27 | AC | 4,681 ms
286,656 KB |
testcase_28 | AC | 4,834 ms
281,464 KB |
testcase_29 | AC | 4,822 ms
284,648 KB |
testcase_30 | AC | 1,580 ms
268,460 KB |
testcase_31 | AC | 1,550 ms
268,460 KB |
testcase_32 | AC | 147 ms
94,508 KB |
testcase_33 | AC | 3,972 ms
282,640 KB |
testcase_34 | AC | 2,060 ms
269,260 KB |
testcase_35 | AC | 2,051 ms
269,380 KB |
ソースコード
from collections import deque def main(): n, q = map(int, input().split()) # ---------------segtree--------------- SIZE = 1 << 17 LOG = 17 d = [(0, 0, 0, 0) for _ in range(SIZE * 2)] # (lmax, rmax, max, sum) def op(s, t): return (max(s[0], s[3] + t[0]), max(t[1], s[1] + t[3]), max(s[2], t[2], s[1] + t[0]), s[3] + t[3]) def seg_init(): for i in range(n): d[SIZE + i] = (1, 1, 1, 1) for i in range(SIZE - 1, 0, -1): seg_update(i) def seg_prod(l, r): # assert 0 <= l and l <= r and r <= self.n sml = (0, 0, 0, 0) smr = (0, 0, 0, 0) l += SIZE r += SIZE while l < r: if l & 1: sml = op(sml, d[l]) l += 1 if r & 1: smr = op(d[r - 1], smr) r -= 1 l >>= 1 r >>= 1 return op(sml, smr) def seg_set(p, x): # assert 0 <= p and p < n p += SIZE d[p] = x for i in range(1, LOG + 1): seg_update(p >> i) def seg_update(k): d[k] = op(d[2 * k], d[2 * k + 1]) # ---------------segtree--------------- a = list(map(int, input().split())) for i in range(n): a[i] -= 1 l = [] r = [] for _ in range(q): li, ri = map(int, input().split()) l.append(li - 1) r.append(ri) p = [(a[i], i) for i in range(n)] p.sort() lo = [-1] * q hi = [n] * q mi_num = [deque() for _ in range(n)] for i in range(q): mi_num[(lo[i] + hi[i]) >> 1].append(i) ans_cnt = 0 while ans_cnt < q: seg_init() for mi in range(n): seg_set(p[mi][1], (-1, -1, -1, -1)) while len(mi_num[mi]) > 0: i = mi_num[mi].popleft() s = seg_prod(l[i], r[i]) if s[3] < 0 or s[3] - s[2] + 1 < 0: hi[i] = mi else: lo[i] = mi if hi[i] - lo[i] > 1: mi_num[lo[i] + ((hi[i] - lo[i]) >> 1)].append(i) else: ans_cnt += 1 for i in range(q): print(p[hi[i]][0] + 1) main()