結果
問題 |
No.1827 最長部分スーパーリッチ門松列列
|
ユーザー |
👑 ![]() |
提出日時 | 2022-01-28 22:18:42 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,077 bytes |
コンパイル時間 | 3,835 ms |
コンパイル使用メモリ | 250,736 KB |
実行使用メモリ | 35,584 KB |
最終ジャッジ日時 | 2024-12-30 07:50:41 |
合計ジャッジ時間 | 47,422 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 TLE * 18 |
ソースコード
#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(); }