1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <cstdio> #include <cmath> #include <algorithm> using namespace std; template <class Type> void read(Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; flag && (x = ~x + 1); } template <class Type> void write(Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar(x % 10 + '0'); } const int N = 5e5 + 10; int n, w[N]; double f[N], g[N]; void solve1 (int l, int r, int L, int R) { if (l > r) return; int mid = l + r >> 1, p = mid; f[mid] = w[mid]; for (int i = L; i <= min(R, mid - 1); i++) { double t = w[i] + sqrt(mid - i); t > f[mid] && (f[mid] = t, p = i); } solve1(l, mid - 1, L, p), solve1(mid + 1, r, p, R); } void solve2 (int l, int r, int L, int R) { if (l > r) return; int mid = l + r >> 1, p = mid; g[mid] = w[mid]; for (int i = max(L, mid + 1); i <= R; i++) { double t = w[i] + sqrt(i - mid); t > g[mid] && (g[mid] = t, p = i); } solve2(l, mid - 1, L, p), solve2(mid + 1, r, p, R); } int main () { read(n); for (int i = 1; i <= n; i++) read(w[i]); solve1(1, n, 1, n), solve2(1, n, 1, n); for (int i = 1; i <= n; i++) write(max(0, (int)ceil(max(f[i], g[i])) - w[i])), puts(""); return 0; }
|