結果
| 問題 |
No.1827 最長部分スーパーリッチ門松列列
|
| コンテスト | |
| ユーザー |
pockyny
|
| 提出日時 | 2022-01-28 22:15:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 146 ms / 2,000 ms |
| コード長 | 1,132 bytes |
| コンパイル時間 | 731 ms |
| コンパイル使用メモリ | 94,340 KB |
| 最終ジャッジ日時 | 2025-01-27 16:44:50 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
#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";
}
}
pockyny