結果
問題 | No.2248 max(C)-min(C) |
ユーザー | tamato |
提出日時 | 2023-03-17 22:46:38 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,423 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 258,832 KB |
最終ジャッジ日時 | 2024-09-18 11:56:16 |
合計ジャッジ時間 | 28,330 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
58,624 KB |
testcase_01 | AC | 42 ms
52,992 KB |
testcase_02 | AC | 40 ms
53,120 KB |
testcase_03 | AC | 119 ms
77,088 KB |
testcase_04 | AC | 100 ms
76,672 KB |
testcase_05 | AC | 85 ms
76,544 KB |
testcase_06 | AC | 146 ms
77,568 KB |
testcase_07 | AC | 123 ms
78,080 KB |
testcase_08 | AC | 148 ms
78,656 KB |
testcase_09 | AC | 139 ms
78,116 KB |
testcase_10 | AC | 80 ms
73,728 KB |
testcase_11 | AC | 134 ms
77,696 KB |
testcase_12 | AC | 120 ms
77,692 KB |
testcase_13 | AC | 148 ms
78,228 KB |
testcase_14 | AC | 144 ms
77,440 KB |
testcase_15 | AC | 146 ms
78,336 KB |
testcase_16 | AC | 116 ms
77,608 KB |
testcase_17 | AC | 123 ms
77,824 KB |
testcase_18 | AC | 1,198 ms
241,676 KB |
testcase_19 | AC | 238 ms
102,432 KB |
testcase_20 | AC | 1,432 ms
258,832 KB |
testcase_21 | AC | 1,452 ms
257,476 KB |
testcase_22 | AC | 1,081 ms
254,808 KB |
testcase_23 | AC | 669 ms
173,572 KB |
testcase_24 | AC | 363 ms
118,416 KB |
testcase_25 | AC | 1,247 ms
257,368 KB |
testcase_26 | AC | 1,173 ms
249,800 KB |
testcase_27 | AC | 1,226 ms
255,456 KB |
testcase_28 | AC | 239 ms
98,432 KB |
testcase_29 | AC | 1,346 ms
256,028 KB |
testcase_30 | AC | 634 ms
162,736 KB |
testcase_31 | AC | 1,468 ms
258,588 KB |
testcase_32 | AC | 368 ms
123,520 KB |
testcase_33 | AC | 544 ms
150,748 KB |
testcase_34 | AC | 1,481 ms
258,580 KB |
testcase_35 | AC | 1,393 ms
258,716 KB |
testcase_36 | AC | 1,368 ms
258,584 KB |
testcase_37 | AC | 805 ms
208,864 KB |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
ソースコード
import sys input = sys.stdin.readline from bisect import bisect_left mod = 998244353 class SegmentTree: def __init__(self, A, initialize=True, segfunc=min, ident=2000000000): self.N = len(A) self.LV = (self.N - 1).bit_length() self.N0 = 1 << self.LV self.segfunc = segfunc self.ident = ident if initialize: self.data = [self.ident] * self.N0 + A + [self.ident] * (self.N0 - self.N) for i in range(self.N0 - 1, 0, -1): self.data[i] = segfunc(self.data[i * 2], self.data[i * 2 + 1]) else: self.data = [self.ident] * (self.N0 * 2) def update(self, i, x): i += self.N0 - 1 self.data[i] = x for _ in range(self.LV): i >>= 1 self.data[i] = self.segfunc(self.data[i * 2], self.data[i * 2 + 1]) def get(self, i): return self.data[i + self.N0 - 1] # open interval [l, r) def query(self, l, r): l += self.N0 - 1 r += self.N0 - 1 ret_l = self.ident ret_r = self.ident while l < r: if l & 1: ret_l = self.segfunc(ret_l, self.data[l]) l += 1 if r & 1: ret_r = self.segfunc(self.data[r - 1], ret_r) r -= 1 l >>= 1 r >>= 1 return self.segfunc(ret_l, ret_r) # return smallest i(l <= i < r) s.t. check(A[i]) == True def binsearch(self, l, r, check): if not check(self.query(l, r)): return r l += self.N0 - 1 val = self.ident while True: if check(self.segfunc(val, self.data[l])): break if l & 1: val = self.segfunc(val, self.data[l]) l += 1 l >>= 1 while l < self.N0: newval = self.segfunc(val, self.data[l * 2]) if not check(newval): val = newval l = (l << 1) + 1 else: l <<= 1 return l - self.N0 + 1 N = int(input()) A_ori = list(map(int, input().split())) B_ori = list(map(int, input().split())) X = [] for a, b in zip(A_ori, B_ori): if a > b: a, b = b, a X.append((a, b, (a + b) // 2)) X.sort(key=lambda x: x[2]) A = [] B = [] AB = [] val = set() for a, b, ab in X: A.append(a) B.append(b) AB.append(ab) val.add(a) val.add(b) val.add(ab) ST_A_min = SegmentTree(A) ST_A_max = SegmentTree(A, initialize=True, segfunc=max, ident=-2000000000) ST_B_min = SegmentTree(B) ST_B_max = SegmentTree(B, initialize=True, segfunc=max, ident=-2000000000) prev = -1 ans = min(max(A) - min(A), max(B) - min(B)) for v in sorted(list(val)): i = bisect_left(AB, v) if i != 0: mi_B = ST_B_min.query(1, i + 1) ma_B = ST_B_max.query(1, i + 1) if mi_B < v: continue else: ma_B = -1 mi_B = 10 ** 10 ok = max(ma_B, AB[-1]) ng = min(v, ma_B) - 1 mid = (ok + ng) // 2 while ok - ng > 1: r = bisect_left(AB, mid + 1) flg = 1 if r != N: mi_A = ST_A_min.query(r+1, N+1) ma_A = ST_A_max.query(r+1, N+1) if mi_A < v or ma_A > mid: flg = 0 if flg: ok = mid else: ng = mid mid = (ok + ng) // 2 ans = min(ans, ok - v) print(ans)