結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー 👑 tatyamtatyam
提出日時 2022-01-28 22:18:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,077 bytes
コンパイル時間 3,110 ms
コンパイル使用メモリ 247,932 KB
実行使用メモリ 35,572 KB
最終ジャッジ日時 2023-08-28 20:23:49
合計ジャッジ時間 42,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 26 ms
4,380 KB
testcase_04 AC 467 ms
4,376 KB
testcase_05 AC 467 ms
4,376 KB
testcase_06 AC 467 ms
4,380 KB
testcase_07 AC 1,958 ms
35,468 KB
testcase_08 AC 1,953 ms
35,408 KB
testcase_09 AC 1,951 ms
35,316 KB
testcase_10 AC 1,946 ms
35,452 KB
testcase_11 AC 1,955 ms
35,408 KB
testcase_12 AC 1,942 ms
35,472 KB
testcase_13 AC 1,943 ms
35,380 KB
testcase_14 AC 1,951 ms
35,372 KB
testcase_15 AC 1,960 ms
35,460 KB
testcase_16 AC 1,961 ms
35,368 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 1,993 ms
35,480 KB
testcase_20 AC 1,992 ms
35,548 KB
testcase_21 AC 1,993 ms
35,408 KB
testcase_22 TLE -
testcase_23 AC 1,993 ms
35,472 KB
testcase_24 AC 1,997 ms
35,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
using namespace std;
const int INF = INT_MAX / 2;
void chmax(int& a, int b){ if(a < b) a = b; }

using T = array<array<int, 2>, 2>;
constexpr T e(){ return T{0, -INF, -INF, 0}; }
constexpr T none(T, T){ return e(); }
T op(T a, T b){
    T ans = e();
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < 2; j++)
            for(int k = 0; k < 2; k++)
                chmax(ans[i][k], a[i][j] + b[j][k]);
    return ans;
}
void solve(){
    int n;
    cin >> n;
    atcoder::lazy_segtree<T, none, e, T, op, op, e> seg(n - 1);
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        p--;
        seg.apply(0, p, T{0, 1, -INF, 0});
        seg.apply(p, n - 1, T{0, -INF, 1, 0});
    }
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        const T x = seg.get(i);
        for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) chmax(ans, x[i][j]);
    }
    cout << ans << endl;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--) solve();
}
0