#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vi h(n), pt, pref(n), suf(n);
for_(i, 0, n) {
cin >> h[i];
pref[i] = suf[i] = h[i];
}
for_(i, 0, n) {
if (i*i+1 < n) pt.push_back(i*i+1);
else break;
}
int mx = 0;
for_(i, 0, n) if (h[i] > mx) {
mx = h[i];
for_(k, 0, pt.size()) {
if (i+pt[k] < n) pref[i+pt[k]] = max(pref[i+pt[k]], h[i]+k+1);
else break;
}
}
mx = 0;
for (int i = n-1; i >= 0; i--) if (h[i] > mx) {
mx = h[i];
for_(k, 0, pt.size()) {
if (i-pt[k] >= 0) suf[i-pt[k]] = max(suf[i-pt[k]], h[i]+k+1);
else break;
}
}
for_(i, 1, n) pref[i] = max(pref[i], pref[i-1]);
for (int i = n-2; i >= 0; i--) suf[i] = max(suf[i], suf[i+1]);
for_(i, 0, n) cout << max(pref[i], suf[i]) - h[i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1408 KB |
Output is correct |
2 |
Incorrect |
10 ms |
1280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1920 KB |
Output is correct |
2 |
Correct |
27 ms |
1912 KB |
Output is correct |
3 |
Correct |
21 ms |
2560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
4088 KB |
Output is correct |
2 |
Correct |
47 ms |
3960 KB |
Output is correct |
3 |
Correct |
49 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
7928 KB |
Output is correct |
2 |
Correct |
72 ms |
5880 KB |
Output is correct |
3 |
Correct |
73 ms |
8056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
11128 KB |
Output is correct |
2 |
Correct |
102 ms |
8184 KB |
Output is correct |
3 |
Correct |
106 ms |
11260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
8824 KB |
Output is correct |
2 |
Correct |
104 ms |
8248 KB |
Output is correct |
3 |
Correct |
105 ms |
11384 KB |
Output is correct |