結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー momoyuumomoyuu
提出日時 2023-10-26 14:21:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 1,543 bytes
コンパイル時間 3,658 ms
コンパイル使用メモリ 252,856 KB
実行使用メモリ 29,472 KB
最終ジャッジ日時 2023-10-26 14:22:10
合計ジャッジ時間 13,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 15 ms
4,372 KB
testcase_04 AC 73 ms
4,372 KB
testcase_05 AC 72 ms
4,372 KB
testcase_06 AC 72 ms
4,372 KB
testcase_07 AC 318 ms
29,472 KB
testcase_08 AC 316 ms
29,472 KB
testcase_09 AC 317 ms
29,472 KB
testcase_10 AC 316 ms
29,472 KB
testcase_11 AC 316 ms
29,472 KB
testcase_12 AC 316 ms
29,472 KB
testcase_13 AC 341 ms
29,472 KB
testcase_14 AC 316 ms
29,472 KB
testcase_15 AC 316 ms
29,472 KB
testcase_16 AC 319 ms
29,472 KB
testcase_17 AC 441 ms
29,472 KB
testcase_18 AC 438 ms
29,472 KB
testcase_19 AC 319 ms
29,472 KB
testcase_20 AC 315 ms
29,472 KB
testcase_21 AC 315 ms
29,472 KB
testcase_22 AC 317 ms
29,472 KB
testcase_23 AC 323 ms
29,472 KB
testcase_24 AC 319 ms
29,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


#include<atcoder/segtree>
using dat = array<array<int,2>,2>;

dat op(dat a,dat b){
    dat c = {};
    for(int i = 0;i<2;i++) for(int j = 0;j<2;j++) c[i][j] = -1e9;
    for(int i = 0;i<2;i++) for(int j = 0;j<2;j++) for(int k = 0;k<2;k++) c[i][j] = max(c[i][j],a[i][k] + b[k][j]);
    return c;
}
dat e(){
    dat c = {};
    c[0][1] = c[1][0] = -1e8;
    return c;
}

void solve(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i = 0;i<n;i++) cin>>p[i];
    for(int i = 0;i<n;i++) p[i]--;
    atcoder::segtree<dat,op,e> seg(n);
    int ans = 0;
    for(int i = 0;i<n;i++){
        dat now = {};
        now[1][0] = now[1][1] = -1e9;
        now[0][0] = 0;
        now[0][1] = 1;
        seg.set(i,now);
    }
    vector<int> idx(n,0);
    for(int i = 0;i<n;i++) idx[p[i]] = i;
    ans = max(ans,seg.all_prod()[0][0]);
    ans = max(ans,seg.all_prod()[1][1]);
    ans = max(ans,seg.all_prod()[1][0]);
    ans = max(ans,seg.all_prod()[0][1]);
    for(int i = 0;i<n;i++){
        int ni = idx[i];
        dat now = {};
        now[0][0] = now[0][1] = -1e9;
        now[1][1] = 0;
        now[1][0] = 1;
        seg.set(ni,now);
        ans = max(ans,seg.all_prod()[0][0]);
        ans = max(ans,seg.all_prod()[1][1]);
    ans = max(ans,seg.all_prod()[1][0]);
    ans = max(ans,seg.all_prod()[0][1]);
    }
    cout<<ans<<endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
0