10998 | 2024-06-02 09:38:04 | szil | Watch Towers | cpp17 | Accepted 100/100 | 128ms | 17732 KiB |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int MAXN = 200'001;
struct P {
ll a, b;
P() : a(0), b(0) {}
P(ll x, ll y) : a(x), b(y) {}
ll f(ll x) {
return a*x+b;
}
};
ll h[MAXN];
P tree[4*MAXN];
void add_line(int v, int tl, int tr, P p) {
int tm = (tl + tr) / 2;
bool lef = tree[v].f(tl) < p.f(tl);
bool mid = tree[v].f(tm) < p.f(tm);
if (mid) swap(tree[v], p);
if (tl + 1 == tr) return;
if (lef != mid) add_line(2*v, tl, tm, p);
else add_line(2*v+1, tm, tr, p);
}
ll get_height(int v, int tl, int tr, int x) {
if (tl + 1 == tr) return tree[v].f(x);
int tm = (tl + tr) / 2;
if (x < tm) return max(tree[v].f(x), get_height(2*v, tl, tm, x));
else return max(tree[v].f(x), get_height(2*v+1, tm, tr, x));
}
void solve() {
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 2; i <= n; i++) {
ll a = h[i] - h[i-1];
ll b = h[i] - i * a;
add_line(1, 1, n, {a, b});
}
for (int i = 1; i <= n; i++) {
cout << max(0ll, get_height(1, 1, n, i)-h[i]) << " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 9ms | 12900 KiB | ||||
2 | Accepted | 9ms | 12900 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 13ms | 12904 KiB | ||||
4 | Accepted | 10ms | 13048 KiB | ||||
5 | Accepted | 13ms | 12900 KiB | ||||
6 | Accepted | 13ms | 13028 KiB | ||||
7 | Accepted | 13ms | 12892 KiB | ||||
8 | Accepted | 13ms | 12900 KiB | ||||
9 | Accepted | 10ms | 12828 KiB | ||||
10 | Accepted | 12ms | 12852 KiB | ||||
11 | Accepted | 10ms | 12772 KiB | ||||
12 | Accepted | 9ms | 12868 KiB | ||||
13 | Accepted | 13ms | 12900 KiB | ||||
14 | Accepted | 10ms | 12920 KiB | ||||
15 | Accepted | 12ms | 12772 KiB | ||||
16 | Accepted | 13ms | 13028 KiB | ||||
17 | Accepted | 13ms | 12916 KiB | ||||
18 | Accepted | 13ms | 13048 KiB | ||||
19 | Accepted | 10ms | 12944 KiB | ||||
subtask3 | 31/31 | ||||||
20 | Accepted | 13ms | 12904 KiB | ||||
21 | Accepted | 10ms | 13048 KiB | ||||
22 | Accepted | 13ms | 12900 KiB | ||||
23 | Accepted | 13ms | 13028 KiB | ||||
24 | Accepted | 13ms | 12892 KiB | ||||
25 | Accepted | 13ms | 12900 KiB | ||||
26 | Accepted | 10ms | 12828 KiB | ||||
27 | Accepted | 12ms | 12852 KiB | ||||
28 | Accepted | 10ms | 12772 KiB | ||||
29 | Accepted | 9ms | 12868 KiB | ||||
30 | Accepted | 13ms | 12900 KiB | ||||
31 | Accepted | 10ms | 12920 KiB | ||||
32 | Accepted | 12ms | 12772 KiB | ||||
33 | Accepted | 13ms | 13028 KiB | ||||
34 | Accepted | 13ms | 12916 KiB | ||||
35 | Accepted | 13ms | 13048 KiB | ||||
36 | Accepted | 10ms | 12944 KiB | ||||
37 | Accepted | 14ms | 12964 KiB | ||||
38 | Accepted | 13ms | 13188 KiB | ||||
39 | Accepted | 14ms | 13072 KiB | ||||
40 | Accepted | 14ms | 13028 KiB | ||||
41 | Accepted | 13ms | 12828 KiB | ||||
42 | Accepted | 13ms | 12900 KiB | ||||
43 | Accepted | 13ms | 12920 KiB | ||||
44 | Accepted | 13ms | 12964 KiB | ||||
45 | Accepted | 14ms | 12976 KiB | ||||
46 | Accepted | 14ms | 12900 KiB | ||||
47 | Accepted | 13ms | 12956 KiB | ||||
48 | Accepted | 13ms | 13028 KiB | ||||
subtask4 | 49/49 | ||||||
49 | Accepted | 13ms | 12904 KiB | ||||
50 | Accepted | 10ms | 13048 KiB | ||||
51 | Accepted | 13ms | 12900 KiB | ||||
52 | Accepted | 13ms | 13028 KiB | ||||
53 | Accepted | 13ms | 12892 KiB | ||||
54 | Accepted | 13ms | 12900 KiB | ||||
55 | Accepted | 10ms | 12828 KiB | ||||
56 | Accepted | 12ms | 12852 KiB | ||||
57 | Accepted | 10ms | 12772 KiB | ||||
58 | Accepted | 9ms | 12868 KiB | ||||
59 | Accepted | 13ms | 12900 KiB | ||||
60 | Accepted | 10ms | 12920 KiB | ||||
61 | Accepted | 12ms | 12772 KiB | ||||
62 | Accepted | 13ms | 13028 KiB | ||||
63 | Accepted | 13ms | 12916 KiB | ||||
64 | Accepted | 13ms | 13048 KiB | ||||
65 | Accepted | 10ms | 12944 KiB | ||||
66 | Accepted | 14ms | 12964 KiB | ||||
67 | Accepted | 13ms | 13188 KiB | ||||
68 | Accepted | 14ms | 13072 KiB | ||||
69 | Accepted | 14ms | 13028 KiB | ||||
70 | Accepted | 13ms | 12828 KiB | ||||
71 | Accepted | 13ms | 12900 KiB | ||||
72 | Accepted | 13ms | 12920 KiB | ||||
73 | Accepted | 13ms | 12964 KiB | ||||
74 | Accepted | 14ms | 12976 KiB | ||||
75 | Accepted | 14ms | 12900 KiB | ||||
76 | Accepted | 13ms | 12956 KiB | ||||
77 | Accepted | 13ms | 13028 KiB | ||||
78 | Accepted | 13ms | 13064 KiB | ||||
79 | Accepted | 13ms | 12756 KiB | ||||
80 | Accepted | 13ms | 13072 KiB | ||||
81 | Accepted | 12ms | 12900 KiB | ||||
82 | Accepted | 13ms | 13028 KiB | ||||
83 | Accepted | 16ms | 13084 KiB | ||||
84 | Accepted | 14ms | 13156 KiB | ||||
85 | Accepted | 14ms | 13324 KiB | ||||
86 | Accepted | 119ms | 17588 KiB | ||||
87 | Accepted | 119ms | 17668 KiB | ||||
88 | Accepted | 122ms | 17656 KiB | ||||
89 | Accepted | 123ms | 17544 KiB | ||||
90 | Accepted | 120ms | 17636 KiB | ||||
91 | Accepted | 123ms | 17732 KiB | ||||
92 | Accepted | 123ms | 17636 KiB | ||||
93 | Accepted | 120ms | 17728 KiB | ||||
94 | Accepted | 128ms | 16740 KiB | ||||
95 | Accepted | 123ms | 16848 KiB | ||||
96 | Accepted | 123ms | 16744 KiB | ||||
97 | Accepted | 123ms | 16892 KiB |