結果
問題 | No.2223 Merged Med |
ユーザー | Shirotsume |
提出日時 | 2023-02-16 21:16:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 5,967 ms / 7,000 ms |
コード長 | 2,410 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 82,096 KB |
実行使用メモリ | 290,980 KB |
最終ジャッジ日時 | 2024-07-19 12:02:29 |
合計ジャッジ時間 | 91,688 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
89,984 KB |
testcase_01 | AC | 88 ms
89,984 KB |
testcase_02 | AC | 117 ms
100,480 KB |
testcase_03 | AC | 86 ms
89,984 KB |
testcase_04 | AC | 112 ms
100,352 KB |
testcase_05 | AC | 126 ms
101,120 KB |
testcase_06 | AC | 85 ms
89,984 KB |
testcase_07 | AC | 129 ms
100,992 KB |
testcase_08 | AC | 130 ms
100,736 KB |
testcase_09 | AC | 127 ms
100,736 KB |
testcase_10 | AC | 131 ms
101,320 KB |
testcase_11 | AC | 89 ms
90,056 KB |
testcase_12 | AC | 122 ms
100,704 KB |
testcase_13 | AC | 2,092 ms
254,528 KB |
testcase_14 | AC | 1,300 ms
190,172 KB |
testcase_15 | AC | 3,866 ms
277,596 KB |
testcase_16 | AC | 5,140 ms
288,908 KB |
testcase_17 | AC | 2,483 ms
278,176 KB |
testcase_18 | AC | 1,253 ms
190,120 KB |
testcase_19 | AC | 1,947 ms
245,416 KB |
testcase_20 | AC | 5,967 ms
284,840 KB |
testcase_21 | AC | 5,877 ms
281,584 KB |
testcase_22 | AC | 5,647 ms
280,548 KB |
testcase_23 | AC | 5,636 ms
282,944 KB |
testcase_24 | AC | 5,722 ms
281,172 KB |
testcase_25 | AC | 5,849 ms
283,348 KB |
testcase_26 | AC | 5,830 ms
282,240 KB |
testcase_27 | AC | 5,486 ms
283,304 KB |
testcase_28 | AC | 5,723 ms
280,556 KB |
testcase_29 | AC | 5,623 ms
285,704 KB |
testcase_30 | AC | 1,774 ms
277,336 KB |
testcase_31 | AC | 1,756 ms
277,368 KB |
testcase_32 | AC | 142 ms
95,872 KB |
testcase_33 | AC | 4,594 ms
290,980 KB |
testcase_34 | AC | 2,212 ms
265,916 KB |
testcase_35 | AC | 2,204 ms
265,800 KB |
ソースコード
from collections import deque import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) Mi = lambda: map(int, input().split()) Li = lambda: list(Mi()) inf = 2 ** 63 - 1 mod = 998244353 def main(): # ---------------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--------------- import random n, q = Mi() a = Li() for i in range(n): a[i] -= 1 l = [] r = [] for _ in range(q): li, ri = Li() 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 = [[] 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].pop() 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()