This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define maxc 1000000007
#define N 510005
using namespace std;
int n, a[N], x2[N], res[N], lef[N], rig[N];
void inline MAX(int &A, int B) {A = max(A, B);}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= sqrt(n) + 1; i++)
x2[i] = i*i;
for (int i = 1; i <= n; i++)
lef[i] = max(a[i], lef[i-1]);
for (int i = n; i >= 1; i--)
rig[i] = max(a[i], rig[i+1]);
for (int i = 1; i <= n; i++)
{
for (int j = 1; i - x2[j-1] - 1 > 0; j++)
MAX(res[i], lef[i - x2[j-1] - 1] + j);
}
for (int i = n; i >= 1; i--)
{
for (int j = 1; i + x2[j-1] + 1 <= n; j++)
MAX(res[i], rig[i + x2[j-1] + 1] + j);
}
for (int i = 1; i <= n; i++)
if (res[i] <= a[i]) cout <<0<<'\n';
else cout <<res[i] - a[i]<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |