#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void self_max(int& me, int other) {
me = max(me, other);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for(int& i : a) {
cin >> i;
}
vector<int> ans(n, 0);
for(int sz = 1, p = 1; p*p < n; p++, sz = p*p) {
multiset<int> s{3};
//if (sz == 1) cout << p << " " << a[sz] << " " << *s.rend() << ": " << (p - a[sz] + *s.rend()) << "\n";
self_max(ans[sz], p + *s.rbegin() - a[sz]);
for(int r = sz; r < n; r++) {
//rem(a[r-sz]);
//s.insert(a[r]);
//if (r-sz == 1) cout << p << " " << a[r-sz] << " " << *s.rend() << "\n";
self_max(ans[r-sz], p - a[r-sz] + *s.rbegin());
//if (r != n-1) {
//self_max(ans[r+1], p - a[r+1] + *s.rbegin());
if (r+1 == 1) cout << p << " " << a[r+1] << " " << *s.rend() << "\n";
//}
}
//for(int i : s) {
//cout << i << " ";
//}
//cout << "\n";
}
//multiset<int> s;
//for(int i = 0; i < n-1; i++) {
//s.insert(a[i]);
//int dist = ceil(sqrt(i+1));
//cout << i+1 << ": " << ceil(sqrt(i+1)) << " " << a[i+1] << " " << *s.rbegin() << "\n";
//self_max(ans[i+1], dist - a[i+1] + *s.rbegin());
//}
//s.clear();
//for(int i = n-1; i >= 1; i--) {
//s.insert(a[i]);
//int dist = ceil(sqrt(n-i));
//self_max(ans[i-1], dist - a[i-1] + *s.rbegin());
//}
for(int i = 0; i < n; i++) {
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
80 ms |
1212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
269 ms |
2508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
475 ms |
3660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
771 ms |
5124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
800 ms |
5128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |