結果
問題 | No.1827 最長部分スーパーリッチ門松列列 |
ユーザー | JiKuai |
提出日時 | 2022-01-28 22:37:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 946 ms / 2,000 ms |
コード長 | 2,807 bytes |
コンパイル時間 | 2,143 ms |
コンパイル使用メモリ | 203,092 KB |
最終ジャッジ日時 | 2025-01-27 17:02:08 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
/* -------------- | / | | / | | / | * |/ | | ------ * | | | | / \ | | |\ | | | |\ | \ | | | \ | | | | \ | \ | | | \ | | \ / \ | V | | \ \__/| ----- \ | */ #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n" #define print(x) emilia_mata_tenshi(#x, begin(x), end(x)) template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) { cerr << "\e[1;33m" << s << " = ["; while(l != r) { cerr << *l; cerr << (++l == r ? ']' : ','); } cerr << "\e[0m\n"; } #define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL); using ll = int64_t; using ull = uint64_t; using ld = long double; using uint = uint32_t; const double EPS = 1e-8; const int INF = 0x3F3F3F3F; const ll LINF = 4611686018427387903; const int MOD = 1e9+7; static int Lamy_is_cute = []() { EmiliaMyWife return 48763; }(); /*--------------------------------------------------------------------------------------*/ const int N = 5e5 + 25; struct segtree { struct node { int ans[4] = {-N, -N, -N, -N}; node() { } node(int x) { if(x) ans[3] = 1; else ans[0] = 1; } } arr[N << 1]; friend node operator+(node a, node b) { node res; for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { if(!(i & 2) != !(j & 1)) res.ans[(i & 1) | (j & 2)] = max(res.ans[(i & 1) | (j & 2)], a.ans[i] + b.ans[j]); } res.ans[i] = max(res.ans[i], a.ans[i]); res.ans[i] = max(res.ans[i], b.ans[i]); } return res; } int n; void init(int _n) { n = _n; for(int i = 0; i < n; i++) arr[i + n] = node(0); for(int i = n - 1; i; i--) arr[i] = arr[i << 1] + arr[i << 1 | 1]; } void edt(int p, int v) { for(arr[p += n] = node(v), p >>= 1; p; p >>= 1) arr[p] = arr[p << 1] + arr[p << 1 | 1]; } int que(int l, int r) { node lres, rres; for(l += n, r += n; l < r; l >>= 1, r >>= 1) { if(l & 1) { lres = lres + arr[l++]; } if(r & 1) { rres = arr[--r] + rres; } } lres = lres + rres; return *max_element(lres.ans, lres.ans + 4); } } tree; signed main() { int t; cin >> t; while(t--) { int n; cin >> n; vector<pair<int, int>> arr(n); tree.init(n); for(int i = 0, x; i < n; i++) { cin >> x; arr[i] = {x, i}; } sort(arr.begin(), arr.end()); int ans = 1; for(const auto &[_, i] : arr) { tree.edt(i, 1); ans = max(ans, tree.que(0, n)); } cout << ans << '\n'; } }