結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー JiKuaiJiKuai
提出日時 2022-01-28 22:37:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 910 ms / 2,000 ms
コード長 2,807 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 206,900 KB
実行使用メモリ 22,716 KB
最終ジャッジ日時 2023-08-28 20:57:44
合計ジャッジ時間 17,266 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
18,972 KB
testcase_01 AC 7 ms
18,940 KB
testcase_02 AC 7 ms
19,004 KB
testcase_03 AC 19 ms
18,960 KB
testcase_04 AC 158 ms
19,020 KB
testcase_05 AC 159 ms
19,004 KB
testcase_06 AC 159 ms
18,996 KB
testcase_07 AC 654 ms
22,648 KB
testcase_08 AC 654 ms
22,600 KB
testcase_09 AC 654 ms
22,616 KB
testcase_10 AC 658 ms
22,716 KB
testcase_11 AC 656 ms
22,604 KB
testcase_12 AC 698 ms
22,596 KB
testcase_13 AC 696 ms
22,604 KB
testcase_14 AC 702 ms
22,636 KB
testcase_15 AC 701 ms
22,572 KB
testcase_16 AC 700 ms
22,576 KB
testcase_17 AC 907 ms
22,660 KB
testcase_18 AC 910 ms
22,596 KB
testcase_19 AC 660 ms
22,608 KB
testcase_20 AC 659 ms
22,612 KB
testcase_21 AC 658 ms
22,716 KB
testcase_22 AC 746 ms
22,548 KB
testcase_23 AC 744 ms
22,552 KB
testcase_24 AC 742 ms
22,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     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';
	}
}
0