結果

問題 No.1188 レベルX門松列
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-08-22 16:14:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 3,276 bytes
コンパイル時間 2,735 ms
コンパイル使用メモリ 204,724 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-23 10:27:40
合計ジャッジ時間 5,718 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
6,652 KB
testcase_01 AC 170 ms
6,392 KB
testcase_02 AC 150 ms
6,196 KB
testcase_03 AC 203 ms
6,784 KB
testcase_04 AC 148 ms
6,780 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 77 ms
6,656 KB
testcase_07 AC 154 ms
6,652 KB
testcase_08 AC 152 ms
6,780 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 18 ms
5,376 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 123 ms
5,564 KB
testcase_15 AC 214 ms
6,640 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 166 ms
6,140 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 156 ms
6,180 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<int> compress1(int *v, int n) {
    vector<int> dic;
    rep(i, 0, n) dic.push_back(v[i]);
    sort(all(dic));
    dic.erase(unique(all(dic)), dic.end());
    rep(i, 0, n) v[i] = lower_bound(all(dic), v[i]) - dic.begin();
    return dic;
}
#define def 0
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2);
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/















int N, _A[101010], A[101010];
//---------------------------------------------------------------------------------------------------
SegTree<int, 1<<17> st;
int lft[101010], rht[101010];
int solve() {
    compress1(A, N);

    rep(i, 0, N) lft[i] = rht[i] = 0;

    rep(i, 0, N) st.update(i, 0);
    rep(i, 0, N) {
        chmax(lft[i], st.get(0, A[i]) + 1);
        st.update(A[i], max(st[A[i]], lft[i]));
    }

    rep(i, 0, N) st.update(i, 0);
    rrep(i, N - 1, 0) {
        chmax(rht[i], st.get(0, A[i]) + 1);
        st.update(A[i], max(st[A[i]], rht[i]));
    }

    int ans = 0;
    rep(i, 0, N) chmax(ans, min(lft[i], rht[i]) - 1);
    return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> _A[i];

    int ans = 0;

    rep(i, 0, N) A[i] = _A[i];
    chmax(ans, solve());

    rep(i, 0, N) A[i] = -_A[i];
    chmax(ans, solve());

    cout << ans << endl;
}




0