結果

問題 No.1188 レベルX門松列
ユーザー leaf_1415leaf_1415
提出日時 2020-08-22 13:58:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 2,078 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 90,552 KB
実行使用メモリ 11,180 KB
最終ジャッジ日時 2024-04-23 08:24:11
合計ジャッジ時間 2,973 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
11,148 KB
testcase_01 AC 104 ms
10,508 KB
testcase_02 AC 100 ms
10,188 KB
testcase_03 AC 126 ms
11,152 KB
testcase_04 AC 79 ms
11,024 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 68 ms
11,028 KB
testcase_07 AC 117 ms
11,180 KB
testcase_08 AC 113 ms
11,156 KB
testcase_09 AC 4 ms
7,268 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 13 ms
6,944 KB
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 71 ms
8,536 KB
testcase_15 AC 122 ms
11,144 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 94 ms
10,292 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 88 ms
10,088 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n;
llint a[100005];
llint l[100005], r[100005];
SegTree seg(17);

void make(llint b[])
{
	seg.init();
	vector<P> vec;
	for(int i = 1; i <= n; i++) vec.push_back(P(a[i], -i));
	sort(vec.begin(), vec.end());
	
	seg.update(0, 0);
	for(int i = 0; i < vec.size(); i++){
		llint p = -vec[i].second;
		b[p] = seg.query(0, p-1) + 1;
		seg.update(p, b[p]);
	}
}

llint calc()
{
	make(l);
	reverse(a+1, a+n+1);
	make(r);
	reverse(a+1, a+n+1);
	
	llint ret = 0;
	for(int i = 1; i <= n; i++) ret = max(ret, min(l[i], r[n+1-i]));
	return ret-1;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = calc();
	for(int i = 1; i <= n; i++) a[i] *= -1;
	ans = max(ans, calc());
	
	cout << ans << endl;
	
	return 0;
}
0