#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 20
const ll MOD = 998244353;
const ll MAXN = 2e5 + 100;
vector<int> h;
vector<int> dp1, dp2;
int sq(int x) {
int l = 0;
int r = 1000;
int ans = 1000;
while (r >= l) {
int mid = l + (r - l) / 2;
if (mid * mid >= x) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
return ans;
}
void dac(vector<int> &dp, int l, int r, int opt_l, int opt_r) {
if (l > r)
return ;
int mx = 0, opt = -1;
int mid = l + (r - l) / 2;
for (int now = opt_l; now <= min(mid, opt_r); now++) {
if (h[now] + sq(mid - now) > mx) {
mx = h[now] + sq(mid - now);
opt = now;
}
}
dp[mid] = mx;
dac(dp, l, mid-1, opt_l, opt);
dac(dp, mid+1, r, opt, opt_r);
}
int main() {
fast
int n;
cin >> n;
h = vector<int>(n+1);
dp1 = vector<int>(n+2);
dp2 = vector<int>(n+2);
for (int i = 1; i <= n; i++)
cin >> h[i];
dac(dp1, 1, n, 1, n);
for (int i = 1; i <= n / 2; i++)
swap(h[i], h[n-i+1]);
dac(dp2, 1, n, 1, n);
for (int i = 1; i <= n; i++)
cout << max(dp1[i], dp2[n - i + 1]) - h[n - i + 1] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2104 KB |
Output is correct |
2 |
Correct |
31 ms |
1616 KB |
Output is correct |
3 |
Incorrect |
30 ms |
1876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2804 KB |
Output is correct |
2 |
Correct |
50 ms |
2896 KB |
Output is correct |
3 |
Incorrect |
48 ms |
2900 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
6396 KB |
Output is correct |
2 |
Correct |
118 ms |
6196 KB |
Output is correct |
3 |
Incorrect |
114 ms |
5988 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
11428 KB |
Output is correct |
2 |
Correct |
187 ms |
9180 KB |
Output is correct |
3 |
Incorrect |
181 ms |
9948 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
15908 KB |
Output is correct |
2 |
Correct |
276 ms |
12996 KB |
Output is correct |
3 |
Incorrect |
260 ms |
14160 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
284 ms |
13728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |