結果

問題 No.1435 Mmm......
ユーザー kwm_tkwm_t
提出日時 2021-03-20 00:26:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,611 bytes
コンパイル時間 4,027 ms
コンパイル使用メモリ 231,340 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2024-04-29 20:24:56
合計ジャッジ時間 6,016 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 32 ms
23,680 KB
testcase_07 AC 35 ms
24,576 KB
testcase_08 AC 40 ms
25,600 KB
testcase_09 AC 37 ms
25,088 KB
testcase_10 AC 35 ms
24,192 KB
testcase_11 AC 34 ms
24,192 KB
testcase_12 AC 32 ms
24,064 KB
testcase_13 AC 31 ms
23,680 KB
testcase_14 AC 21 ms
14,592 KB
testcase_15 AC 40 ms
25,600 KB
testcase_16 AC 36 ms
24,704 KB
testcase_17 AC 23 ms
14,848 KB
testcase_18 AC 40 ms
25,984 KB
testcase_19 AC 33 ms
24,064 KB
testcase_20 AC 38 ms
25,216 KB
testcase_21 AC 69 ms
25,728 KB
testcase_22 AC 57 ms
25,856 KB
testcase_23 AC 49 ms
25,856 KB
testcase_24 AC 49 ms
25,856 KB
testcase_25 AC 48 ms
25,728 KB
testcase_26 AC 49 ms
25,856 KB
testcase_27 AC 49 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;
}

long long target;

bool f(seginfo v) {
	return v.data <= target;
}


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;
	target = 0;
	rep(i, N - 1) {
		/*
			m1,m2は減少、Mは増加
			よって、M-m1-m2は増加する。
			これが <=0ならばいい
		*/
		ans += seg.max_right<f>(i) - i - 1;
	}
	cout << ans << endl;
	return 0;
}
0