結果

問題 No.1188 レベルX門松列
ユーザー risujirohrisujiroh
提出日時 2020-08-22 13:23:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,493 bytes
コンパイル時間 3,809 ms
コンパイル使用メモリ 260,040 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 07:46:55
合計ジャッジ時間 5,166 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 56 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
  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];
  int res = 0;
  for (int i = 0; i < n; ++i) res = max(res, min(l[i], r[i]));
  cout << res << '\n';
}
0