Submission #968220

# Submission time Handle Problem Language Result Execution time Memory
968220 2024-04-23T08:33:46 Z Gromp15 Real Mountains (CCO23_day1problem2) C++17
0 / 25
0 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int mod = 1000003;
void test_case() {
	int n; cin >> n;
	vector<int> h(n);
	int mn = 1e9;
	for (int &x : h) cin >> x, ckmin(mn, x);
	int l = -1, r = -1;
	for (int i = 0; i < n; i++) if (h[i] == mn) {
		if (!~l) l = i;
		r = i;
	}
	int c = h[l];
	int ans = 0;
	while (l > 0 && r < n-1) {
		int mn = min(h[l-1], h[r+1]);
		ans += (ll)(r-l+1) * ((((ll)(h[l-1] + h[r+1]) * (mn-c) + (ll)(c+mn-1)*(mn-c)/2)) % mod) % mod;
		ans %= mod;
		while (l && h[l-1] == mn) l--;
		while (r+1 < n && h[r+1] == mn) r++;
		c = mn;
	}
	cout << ans << '\n';
	/*
	vector<int> f(h);
	{
		int l = -1, r = -1;
		for (int i = 0; i < n; i++) if (h[i] == mx) {
			if (!~l) l = i;
			r = i;
		}
		for (int i = l; i <= r; i++) f[i] = mx;
		for (int i = 1; i < l; i++) ckmax(f[i], f[i-1]);
		for (int i = n-2; i > r; i--) ckmax(f[i], f[i+1]);
	}
	int ans = 0;
	const int INF = 1e9;
	for (int t = 1; t < mx; t++) {
		vector<int> pref(n), suff(n);
		for (int i = 0; i < n; i++) {
			pref[i] = min(h[i] > t ? h[i] : INF, i ? pref[i-1] : INF);
		}
		for (int i = n-1; i >= 0; i--) {
			suff[i] = min(h[i] > t ? h[i] : INF, i + 1 < n ? suff[i+1] : INF);
		}
		for (int i = 0; i < n; i++) if (h[i] == t && h[i] < f[i]) {
			assert(min(pref[i], suff[i]) > h[i]);
			assert(pref[i] < INF && suff[i] < INF);
			ans += (pref[i] + suff[i] + h[i]) % mod;
			if (ans >= mod) ans -= mod;
			h[i]++;
		}
	}
	cout << ans << '\n';
	*/
	/*
	int ans = 0;
	vector<int> idx(n);
	iota(all(idx), 0);
	sort(all(idx), [&](int x, int y) { return h[x] < h[y]; });
	for (int _i = 0; _i < n; _i++) {
		int i = idx[_i];
		if (i == 0 || i == n-1 || h[i] == f[i]) continue;
		auto prog = [](int l, int r) {
			return (ll)(l+r)*(r-l+1)/2;
		};
		auto cost = [prog](int l, int r, int extra) {
			return (ll)extra * (r-l) + prog(l, r-1);
		};
		vector<int> l(h.begin(), h.begin() + i), r(h.begin() + i + 1, h.end());
		sort(all(l));
		sort(all(r));
		int a = 0, b = 0;
		while (h[i] < f[i]) {
			if (l[a] <= h[i]) a++;
			else if (r[b] <= h[i]) b++;
			else {
				int to = min({l[a], r[b], f[i]});
				ans += cost(h[i], to, l[a] + r[b]) % mod;
				if (ans >= mod) ans -= mod;
				h[i] = to;
			}
		}
	}
	cout << ans << '\n';
	*/



}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -