Submission #906386

# Submission time Handle Problem Language Result Execution time Memory
906386 2024-01-14T07:25:31 Z Trisanu_Das Lightning Conductor (POI11_pio) C++17
100 / 100
183 ms 14032 KB
#include <bits/stdc++.h>
using namespace std;
 
struct point {
	int i, l, r; //[l...r] => segment of maximality
};
 
int n, h[500005], dp[500005];
deque<point> hull;
 
double f(int x, int i) {
	return h[i] + sqrt(abs(x - i));
}
 
void solve() {
	hull.clear();
	for(int i = 1; i <= n; ++i) {
		while(!hull.empty() && hull.front().r < i) hull.pop_front();
		while(!hull.empty() && f(max(i, hull.back().l), hull.back().i) <= f(max(i, hull.back().l), i)) hull.pop_back();
		if(hull.empty()) hull.push_back({i, i, n});
		else {
			int l = max(i, hull.back().l), r = hull.back().r, ans = 0;
			while(l <= r) {
				int m = (l + r) / 2;
				if(f(m, i) >= f(m, hull.back().i)) ans = m, r = m - 1;
				else l = m + 1;
			}
			if(ans) {
				if(ans - 1 >= hull.back().l) hull.back().r = ans - 1;
				else hull.pop_back();
				hull.push_back({i, ans, n});
			}
		}
		dp[i] = max(dp[i], (int)ceil(f(i, hull.front().i)) - h[i]);
	}
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> h[i];
	solve();
	reverse(h + 1, h + 1 + n);
	reverse(dp + 1, dp + 1 + n);
	solve();
	for(int i = n; i; --i) cout << dp[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3412 KB Output is correct
2 Correct 19 ms 2908 KB Output is correct
3 Correct 20 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4188 KB Output is correct
2 Correct 32 ms 3924 KB Output is correct
3 Correct 30 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 6452 KB Output is correct
2 Correct 75 ms 6084 KB Output is correct
3 Correct 71 ms 6144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 10688 KB Output is correct
2 Correct 119 ms 8480 KB Output is correct
3 Correct 111 ms 9300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 14032 KB Output is correct
2 Correct 171 ms 11092 KB Output is correct
3 Correct 164 ms 12212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 11604 KB Output is correct
2 Correct 183 ms 11052 KB Output is correct
3 Correct 169 ms 12240 KB Output is correct