結果

問題 No.1188 レベルX門松列
ユーザー iqueue02iqueue02
提出日時 2020-08-22 16:56:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,271 bytes
コンパイル時間 2,888 ms
コンパイル使用メモリ 210,132 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-23 11:02:24
合計ジャッジ時間 5,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 22 ms
5,376 KB
testcase_07 AC 129 ms
5,504 KB
testcase_08 AC 130 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
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 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
template <typename T> 
struct SegmentTree {
  
  int n;
  vector<T> node;

  T f(T a, T b) {return max(a, b);}

  SegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
    for (int i = n - 2; i >= 0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
  }

  void update(int k, T x) {
    k += (n - 1);
    node[k] = x;
    while (k > 0) {
      k = (k - 1) >> 1;
      node[k] = f(node[2*k+1], node[2*k+2]);
    } 
  }

  void clear(T init = 0) {
    for (int i = 0; i < 2 * n; i++) node[i] = init;
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }

  T getvalue(int k) {
    return query(k,k+1);
  }

};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  auto b = a;
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());

  int m = b.size();
  int res = 0;
  SegmentTree<int> seg(m);

  vector<int> dpl(n, 0), dpr(n, 0);

  auto make_id = [&](int x){ 
    return lower_bound(b.begin(), b.end(), x) - b.begin();
  };

  for (int i = 0; i < n; i++) {
    int id = make_id(a[i]);
    dpl[i] = seg.query(id + 1, m) + 1;
    seg.update(id, dpl[i]);
  }

  seg.clear();

  for (int i = n - 1; i >= 0; i--) {
    int id = make_id(a[i]);
    dpr[i] = seg.query(id + 1, m) + 1;
    seg.update(id, dpr[i]);
  }

  for (int i = 0; i < n; i++) {
    res = max(res, min(dpl[i], dpr[n - i - 1]));
  }
  
  for (int i = 0; i < n; i++) dpl[i] = 0, dpr[i] = 0;
  seg.clear();

  for (int i = n - 1; i >= 0; i--) {
    int id = make_id(a[i]);
    dpr[i] = seg.query(0, id) + 1;
    seg.update(id, dpr[i]);
  }

  seg.clear();

  for (int i = 0; i < n; i++) {
    int id = make_id(a[i]);
    dpl[i] = seg.query(0, id) + 1;
    seg.update(id, dpl[i]);
  }
  
  for (int i = 0; i < n; i++) {
    res = max(res, min(dpl[i], dpr[n - i - 1]));
  }

  cout << res - 1 << endl;
  return 0;
}
0