結果

問題 No.3017 交互浴
ユーザー mihhiael
提出日時 2025-01-25 14:00:51
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 140,772 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2025-01-25 23:05:06
合計ジャッジ時間 9,464 ms
ジャッジサーバーID
(参考情報)
judge3 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

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<pall> segs;
	ll ans = 0;
	ll i = -1;
	for(const auto &e:h) {
		i++;
		vector<decltype(segs)::value_type> dels;
		for(const auto &f:segs) {
			if(f.first < e) {
				dels.push_back(f);
				if(f.second > e) {
					auto v = f;
					v.first = e;
					segs.insert(v);
					ans += v.second - v.first;
					break;
				}
			} else break;
		}
		for(const auto &e:dels) {
			ans -= e.second - e.first;
			segs.erase(e);
		}
		if(i % 2 == cyan) {
			ans += e;
			segs.insert({0, e});
		}
		cout << ans << "\n";
	}
}
0