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>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
//#define endl '\n'
const int MXV = 1e6, INF = 1e9;
int rt[MXV+1];
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<ii> pos(MXV+1, {INF, -1});
int n; cin >> n;
vi h(n);
int mx = 0;
for_(i, 0, n) {
cin >> h[i];
mx = max(mx, h[i]);
pos[h[i]] = {min(pos[h[i]].first, i), max(pos[h[i]].second, i)};
}
int r = 0, sq = 0;
for_(i, 0, mx+1) {
rt[i] = r;
if (i == sq) {
r += 1;
sq = r*r;
}
}
vi poss;
for (int i = mx; i >= max(mx-710, 0); i--) if (pos[i].first != INF) {
poss.push_back(i);
}
for_(i, 0, n) {
int ans = 0;
for (auto v: poss) ans = max({ans, v + rt[abs(pos[v].first - i)], v + rt[abs(pos[v].second - i)]});
cout << max(ans-h[i], 0) << endl;
}
return 0;
}
# | 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... |