結果

問題 No.1435 Mmm......
ユーザー kwm_tkwm_t
提出日時 2021-03-20 00:19:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 1,674 bytes
コンパイル時間 3,762 ms
コンパイル使用メモリ 232,668 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2024-04-29 20:18:41
合計ジャッジ時間 10,203 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 168 ms
23,832 KB
testcase_07 AC 207 ms
24,700 KB
testcase_08 AC 246 ms
25,600 KB
testcase_09 AC 223 ms
25,088 KB
testcase_10 AC 191 ms
24,320 KB
testcase_11 AC 187 ms
24,336 KB
testcase_12 AC 172 ms
23,924 KB
testcase_13 AC 167 ms
23,808 KB
testcase_14 AC 120 ms
14,592 KB
testcase_15 AC 264 ms
25,728 KB
testcase_16 AC 207 ms
24,704 KB
testcase_17 AC 138 ms
14,976 KB
testcase_18 AC 260 ms
25,852 KB
testcase_19 AC 184 ms
24,244 KB
testcase_20 AC 237 ms
25,292 KB
testcase_21 AC 429 ms
25,984 KB
testcase_22 AC 427 ms
25,828 KB
testcase_23 AC 273 ms
25,852 KB
testcase_24 AC 272 ms
25,836 KB
testcase_25 AC 270 ms
25,828 KB
testcase_26 AC 275 ms
25,856 KB
testcase_27 AC 273 ms
25,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
struct seginfo {
	long long min1, min2, max1;
	long long data;
	seginfo() {};
	seginfo(long long _min1, long long _min2, long long _max1) :min1(_min1), min2(_min2), max1(_max1) {
		data = max1 - min1 - min2;
	}
};

seginfo op(seginfo a, seginfo b) {

	long long _min1 = min(a.min1, b.min1);
	long long _min2 = min(max(a.min1, b.min1), min(a.min2, b.min2));
	long long _max1 = max(a.max1, b.max1);
	seginfo s(_min1, _min2, _max1);
	return s;
}

seginfo e() {
	seginfo s(INF, INF, -INF);
	return s;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<seginfo>A(N + 1);
	rep(i, N) {
		int num;
		cin >> num;
		A[i] = seginfo(num, INF, num);
	}
	A[N] = seginfo(LINF, LINF, LINF);
	segtree<seginfo, op, e>seg(A);
	long long ans = 0;
	rep(i, N - 1) {
		/*
			m1,m2は減少、Mは増加
			M-m1-m2は増加する。
			これが <=0ならばいい
		*/
		int ng = N + 1;
		int ok = i + 2;
		while (1 < abs(ok - ng)) {
			int c = (ng + ok) / 2;
			if (seg.prod(i, c).data <= 0) {
				ok = c;
			}
			else {
				ng = c;
			}
		}
		ans += ok - i - 1;
	}
	cout << ans << endl;
	return 0;
}
0