結果

問題 No.1188 レベルX門松列
ユーザー risujirohrisujiroh
提出日時 2020-08-22 13:26:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 3,075 ms
コンパイル使用メモリ 268,828 KB
実行使用メモリ 5,320 KB
最終ジャッジ日時 2023-08-05 10:30:07
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
5,236 KB
testcase_01 AC 82 ms
4,864 KB
testcase_02 AC 72 ms
4,872 KB
testcase_03 AC 103 ms
5,272 KB
testcase_04 AC 59 ms
5,276 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 54 ms
5,316 KB
testcase_07 AC 56 ms
5,184 KB
testcase_08 AC 55 ms
5,208 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 60 ms
4,588 KB
testcase_15 AC 104 ms
5,320 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 81 ms
4,852 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 75 ms
4,768 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

template <class T>
struct segtree {
  int n;
  vector<T> t;
  segtree(int _n = 0) : n(_n), t(2 * n) {}
  T& operator[](int i) { return t[n + i]; }
  void build() {
    for (int i = n; i-- > 1;) t[i] = t[2 * i] * t[2 * i + 1];
  }
  T fold(int l, int r) const {
    T a{}, b{};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) a = a * t[l++];
      if (r & 1) b = t[--r] * b;
    }
    return a * b;
  }
  void set(int i, const T& a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = t[2 * i] * t[2 * i + 1];
  }
};

struct maxi {
  int v = 0;
  maxi operator*(maxi b) const { return v < b.v ? b : *this; }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  auto f = [&](auto&& a) {
    vector<int> ord(n);
    iota(rbegin(ord), rend(ord), 0);
    stable_sort(begin(ord), end(ord),
                [&](int i, int j) { return a[i] < a[j]; });
    segtree<maxi> seg(n);
    vector<int> res(n);
    for (int i : ord) {
      seg.set(i, {seg.fold(0, i).v + 1});
      res[i] = seg[i].v;
    }
    return res;
  };
  vector<int> a(n);
  for (auto&& e : a) cin >> e;
  int res = 0;
  for (int _ = 2; _--;) {
    auto l = f(a);
    reverse(begin(a), end(a));
    auto t = f(a), r = t;
    for (int i = 0; i < n; ++i) r[i] = t[n - i - 1];
    for (int i = 0; i < n; ++i) res = max(res, min(l[i], r[i]) - 1);
    for (auto&& e : a) e = -e;
  }
  cout << res << '\n';
}
0