#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
const char* end = strchr(names + 1, ',');
cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
printDebug(end, args...);
}
const int MAX_N = 5e5 + 10;
int arr[MAX_N];
int sqr[MAX_N];
int n;
int lftans[MAX_N], rghtans[MAX_N];
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n;
for(int i = 0; i < n; i ++) {
cin >> arr[i];
}
for(int i = 1; i < 1000; i ++) {
for(int j = (i - 1) * (i - 1) + 1; j <= min(i * i, MAX_N - 1); j ++) {
sqr[j] = i;
}
}
for(int i = 0; i < n; i ++) {
if(i != 0) {
lftans[i] = lftans[i - 1];
}
for(int j = 0; j < 1000; j ++) {
if(i - j * j - 1 < 0) {break;}
chkmax(lftans[i], j + 1 + arr[i - j * j - 1]);
}
}
for(int i = n - 1; i >= 0; i --) {
if(i != n - 1) {
rghtans[i] = rghtans[i + 1];
}
for(int j = 0; j < 1000; j ++) {
if(i + j * j + 1 > n - 1) {break;}
chkmax(rghtans[i], j + 1 + arr[i + j * j + 1]);
}
}
for(int i = 0; i < n; i ++) {
cout << max(0, max(lftans[i], rghtans[i]) - arr[i]) << endl;;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
3268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
3328 KB |
Output is correct |
2 |
Correct |
59 ms |
3236 KB |
Output is correct |
3 |
Correct |
51 ms |
3524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
3780 KB |
Output is correct |
2 |
Correct |
95 ms |
3812 KB |
Output is correct |
3 |
Correct |
95 ms |
4396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
332 ms |
6112 KB |
Output is correct |
2 |
Correct |
329 ms |
7848 KB |
Output is correct |
3 |
Correct |
329 ms |
7820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
634 ms |
11048 KB |
Output is correct |
2 |
Correct |
634 ms |
11200 KB |
Output is correct |
3 |
Correct |
631 ms |
11912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
15644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
13308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |