結果
問題 |
No.1827 最長部分スーパーリッチ門松列列
|
ユーザー |
![]() |
提出日時 | 2023-10-26 14:21:56 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 411 ms / 2,000 ms |
コード長 | 1,543 bytes |
コンパイル時間 | 2,969 ms |
コンパイル使用メモリ | 252,096 KB |
実行使用メモリ | 29,428 KB |
最終ジャッジ日時 | 2024-09-25 12:23:57 |
合計ジャッジ時間 | 11,589 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
#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(); } }