#include <bits/stdc++.h>
#define task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 5e5 + 2;
int n, h[N], sq[N], dp[N];
int cost(int i, int j)
{
return h[j] + sq[abs(i - j)];
}
void cal(int l, int r, int optl, int optr)
{
if (l > r) return;
int m = (l + r) >> 1, opt = optl;
rep(k, optl + 1, min(m, optr)) if (cost(m, k) > cost(m, opt)) opt = k;
dp[m] = max(dp[m], cost(m, opt));
cal(l, m - 1, optl, opt);
cal(m + 1, r, opt, optr);
}
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n;
rep(i, 1, n) cin >> h[i];
rep(i, 1, 708)
{
if (i * i >= n)
{
sq[n] = i;
break;
}
sq[i * i] = i;
}
Rep(i, n - 1, 2) if (!sq[i]) sq[i] = sq[i + 1];
cal(1, n, 1, n);
reverse(h + 1, h + 1 + n);
reverse(dp + 1, dp + 1 + n);
cal(1, n, 1, n);
Rep(i, n, 1) cout << dp[i] - h[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
416 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2168 KB |
Output is correct |
2 |
Correct |
14 ms |
1536 KB |
Output is correct |
3 |
Incorrect |
16 ms |
2048 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2928 KB |
Output is correct |
2 |
Correct |
26 ms |
2816 KB |
Output is correct |
3 |
Incorrect |
25 ms |
3064 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
6316 KB |
Output is correct |
2 |
Correct |
60 ms |
6032 KB |
Output is correct |
3 |
Incorrect |
56 ms |
6008 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
11420 KB |
Output is correct |
2 |
Correct |
93 ms |
9336 KB |
Output is correct |
3 |
Incorrect |
89 ms |
9976 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
15952 KB |
Output is correct |
2 |
Correct |
137 ms |
13176 KB |
Output is correct |
3 |
Incorrect |
128 ms |
14200 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
139 ms |
13568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |