結果
問題 | No.1188 レベルX門松列 |
ユーザー | NatsubiSogan |
提出日時 | 2021-11-28 10:17:03 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,367 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 26,760 KB |
最終ジャッジ日時 | 2024-07-01 02:21:56 |
合計ジャッジ時間 | 5,110 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | AC | 39 ms
11,648 KB |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
ソースコード
import typing class SegmentTree: def __init__( self, lis: list, ele: typing.Any, op: typing.Callable[[typing.Any, typing.Any], typing.Any]) -> None: self.n = len(lis) self.log = (self.n - 1).bit_length() self.size = 1 << self.log self.op = op self.ele = ele self.tree = self._build(lis) def _build(self, lis: list) -> list: res_tree = [self.ele] * (2 * self.size) for i, a in enumerate(lis): res_tree[self.size + i] = a for i in range(1, self.size)[::-1]: res_tree[i] = self.op(res_tree[2 * i], res_tree[2 * i + 1]) return res_tree def __getitem__(self, i: int) -> None: return self.tree[self.size + i] def __setitem__(self, p: int, x: int) -> None: p += self.size self.tree[p] = x for i in range(1, self.log + 1): self.tree[p >> i] = self.op(self.tree[2 * (p >> i)], self.tree[2 * (p >> i) + 1]) def prod(self, l: int, r: int) -> typing.Any: l += self.size r += self.size L = R = self.ele while l < r: if l & 1: L = self.op(L, self.tree[l]) l += 1 if r & 1: r -= 1 R = self.op(self.tree[r], R) l >>= 1 r >>= 1 return self.op(L, R) def all_prod(self) -> typing.Any: return self.tree[1] def max_right(self, l: int, f: typing.Callable[[typing.Any], typing.Any]) -> int: if l == self.n: return self.n l += self.size sm = self.ele while True: while l % 2 == 0: l >>= 1 if not f(self.op(sm, self.tree[l])): while l < self.size: l *= 2 if f(self.op(sm, self.tree[l])): sm = self.op(sm, self.tree[l]) l += 1 return l - self.size sm = self.op(sm, self.tree[l]) l += 1 if (l & -l) == l: return self.n def one_d_coordinate_compression(l: list) -> list: n = len(l) sorted_list = sorted(set(l)) d = {sorted_list[i]: i for i in range(len(sorted_list))} return [d[i] for i in l] n = int(input()) A = list(map(int, input().split())) ST = SegmentTree([0] * (n + 10), 0, max) def solve(a): l, r = [0] * n, [0] * n for i in range(n): l[i] = max(l[i], ST.prod(0, a[i]) + 1) ST[a[i]] = max(ST[a[i]], l[i]) for i in range(n + 10): ST[i] = 0 for i in range(n)[::-1]: r[i] = max(r[i], ST.prod(0, a[i]) + 1) ST[a[i]] = max(ST[a[i]], r[i]) res = 0 for i in range(n): res = max(res, min(l[i], r[i]) - 1) return res ans = 0 ans = max(ans, solve(A)) A = [-i for i in A] ans = max(ans, solve(A)) print(ans)