結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー pockynypockyny
提出日時 2022-01-28 22:15:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 79,240 KB
実行使用メモリ 25,140 KB
最終ジャッジ日時 2023-08-28 20:16:51
合計ジャッジ時間 3,890 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 25 ms
4,380 KB
testcase_06 AC 24 ms
4,376 KB
testcase_07 AC 92 ms
25,064 KB
testcase_08 AC 91 ms
25,140 KB
testcase_09 AC 91 ms
24,936 KB
testcase_10 AC 92 ms
24,932 KB
testcase_11 AC 91 ms
24,996 KB
testcase_12 AC 91 ms
24,992 KB
testcase_13 AC 91 ms
24,932 KB
testcase_14 AC 92 ms
25,056 KB
testcase_15 AC 91 ms
24,984 KB
testcase_16 AC 91 ms
25,020 KB
testcase_17 AC 115 ms
25,008 KB
testcase_18 AC 117 ms
24,996 KB
testcase_19 AC 92 ms
24,932 KB
testcase_20 AC 91 ms
25,060 KB
testcase_21 AC 91 ms
24,992 KB
testcase_22 AC 92 ms
24,980 KB
testcase_23 AC 92 ms
24,916 KB
testcase_24 AC 93 ms
25,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/segtree>
#include <vector>

using namespace std;
using namespace atcoder;
struct S{int le,ri,num;};
S e(){ return S{-1,-1,0};}
S op(S a,S b){
    if(a.le==-1 && b.le!=-1) return b;
    if(a.le!=-1 && b.le==-1) return a;
    if(a.le==-1 && b.le==-1) return e();
    int nnum = a.num + b.num + (a.ri!=b.le);
    return {a.le,b.ri,nnum};
}

int p[500010],q[500010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t; cin >> t;
    while(t){
        t--;
        int i,n; cin >> n;
        for(i=0;i<n;i++) cin >> p[i];
        for(i=0;i<n;i++) q[p[i] - 1] = i;
        vector<S> v(n);
        for(i=0;i<n;i++) v[i] = {0,0,0};
        segtree<S,op,e> seg(v);
        int ans = -1;
        for(i=0;i<n;i++){
            int j = q[i];
            seg.set(j,S{1,1,0});
            ans = max(ans,seg.all_prod().num);
            /*for(int j=0;j<n;j++){
                cout << "(" << seg.prod(j,j + 1).le << "," << seg.prod(j,j + 1).ri << "," << seg.prod(j,j + 1).num << ") ";
            }*/
            //cout << endl;
        }
        cout << ans + 1<< "\n";
    }
}
0