#include<bits/stdc++.h>
using namespace std;
int ceil_sqrt(int n){
int x = sqrt(n);
while(x * x < n) ++x;
return x;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> h(n);
vector<vector<int>> st;
st.push_back(vector<int>(n));
for(int i = 0; i < n; ++i){
cin >> h[i];
st[0][i] = h[i];
}
vector<int> lg(n + 1);
lg[1] = 0;
for(int i = 2; i <= n; ++i){
lg[i] = lg[i >> 1] + 1;
}
for(int i = 1; (1 << i) <= n; ++i){
st.push_back(vector<int>(n - (1 << i) + 1));
for(int j = 0; j + (1 << i) <= n; ++j){
st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
}
auto max_range = [&](int l, int r){
int b = lg[r - l + 1];
return max(st[b][l], st[b][r - (1 << b) + 1]);
};
vector<int> p(n);
for(int i = 0; i < n; ++i){
if(i != 0){
int B = ceil_sqrt(i);
for(int k = 1; k <= B; ++k){
p[i] = max(p[i], max_range(max(0, i - k * k), i - (k - 1) * (k - 1) - 1) + k - h[i]);
}
}
if(i != n - 1){
int B = ceil_sqrt(n - 1 - i);
for(int k = 1; k <= B; ++k){
p[i] = max(p[i], max_range(i + (k - 1) * (k - 1) + 1, min(n - 1, i + k * k)) + k - h[i]);
}
}
}
for(int i = 0; i < n; ++i){
cout << p[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
5456 KB |
Output is correct |
2 |
Correct |
102 ms |
5200 KB |
Output is correct |
3 |
Correct |
102 ms |
5456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
7884 KB |
Output is correct |
2 |
Correct |
184 ms |
7884 KB |
Output is correct |
3 |
Correct |
183 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
728 ms |
19296 KB |
Output is correct |
2 |
Correct |
683 ms |
19036 KB |
Output is correct |
3 |
Correct |
712 ms |
19800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
28540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
41296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
41820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |