結果

問題 No.3017 交互浴
ユーザー mihhiael
提出日時 2025-01-25 13:49:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,432 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 142,992 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2025-01-25 23:00:43
合計ジャッジ時間 10,838 ms
ジャッジサーバーID
(参考情報)
judge11 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 50 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <vector>
#include <string>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
using ll  = long long;
using pall = pair<ll,ll>;
using vell = vector<ll>;

template<class T, class U>
constexpr bool mini(T &var, const U &val) noexcept {
	const bool cmp = var > val;
	if(cmp) var = val;
	return cmp;
}
template<class T, class U>
constexpr bool maxi(T &var, const U &val) noexcept {
	const bool cmp = var < val;
	if(cmp) var = val;
	return cmp;
}

void solve();

int main(void) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

enum color {
	cyan = 0,
	green = 1
};

void solve() {
	ll n;
	cin >> n;
	vell h(n);
	for(auto &e:h) cin >> e;
	set<pair<pall, ll>> segs;
	segs.insert({{0, 1e15}, green});
	ll ans = 0;
	ll i = -1;
	for(const auto &e:h) {
		i++;
		vector<decltype(segs)::value_type> dels;
		for(const auto &f:segs) {
			dels.push_back(f);
			if(f.first.second > e) {
				auto v = f;
				v.first.first = e;
				segs.insert(v);
				if(f.second == cyan) ans += f.first.second - e;
				break;
			}
		}
		for(const auto &e:dels) {
			if(e.second == cyan) ans -= e.first.second - e.first.first;
			segs.erase(e);
		}
		segs.insert({{0, e}, i % 2});
		if(i % 2 == cyan) ans += e;
		cout << ans << "\n";
	}
}
0