#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MAXN = (int) 5e5 + 5;
int pref[MAXN + 1], suff[MAXN + 1];
int h[MAXN + 1], sq[1000];
int main() {
//ifstream cin("B.in");
//ofstream cout("B.out");
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for(i = 1; i <= n; i++) {
cin >> h[i];
}
for(i = 1; i < 1000; i++) {
sq[i] = i * i;
}
int mx = 0;
for(int j = 1; j <= n; j++) {
int pos;
if(h[j] > mx) {
pref[j] = max(pref[j], h[j]);
for(i = 1; j + sq[i - 1] < n; i++) {
pos = j + sq[i - 1] + 1;
pref[pos] = max(pref[pos], h[j] + i);
}
}
mx = max(mx, h[j]);
}
mx = 0;
for(int j = n; j >= 1; j--) {
int pos;
if(mx < h[j]) {
suff[j] = max(suff[j], h[j]);
for(i = 1; j - sq[i - 1] - 1 >= 1; i++) {
pos = j - sq[i - 1] - 1;
suff[pos] = max(suff[pos], h[j] + i);
}
}
mx = max(mx, h[j]);
}
for(i = n; i >= 1; i--) {
suff[i] = max(suff[i + 1], suff[i]);
}
for(i = 1; i <= n; i++) {
pref[i] = max(pref[i], pref[i - 1]);
cout << max(pref[i], suff[i]) - h[i] << "\n";
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2048 KB |
Output is correct |
2 |
Incorrect |
10 ms |
1372 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2952 KB |
Output is correct |
2 |
Correct |
20 ms |
2900 KB |
Output is correct |
3 |
Correct |
19 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
5160 KB |
Output is correct |
2 |
Correct |
59 ms |
4900 KB |
Output is correct |
3 |
Correct |
40 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8984 KB |
Output is correct |
2 |
Correct |
67 ms |
6848 KB |
Output is correct |
3 |
Correct |
65 ms |
8988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
11984 KB |
Output is correct |
2 |
Correct |
97 ms |
13176 KB |
Output is correct |
3 |
Correct |
95 ms |
13920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
9720 KB |
Output is correct |
2 |
Correct |
94 ms |
13304 KB |
Output is correct |
3 |
Correct |
94 ms |
14072 KB |
Output is correct |