#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef CB
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int N;
cin >> N;
vector<int> v(N);
for (int i = 0; i < N; i++) {
cin >> v[i];
}
vector<int> a(N);
vector<int> b(N);
for (int i = 1; i <= N - 2; i++) {
a[i] = lower_bound(v.begin(), v.end(), v[i] * 2 - v[i - 1]) - v.begin() - 1;
b[i] = lower_bound(v.begin(), v.end(), v[i] * 2 - v[i + 1]) - v.begin();
}
vector<array<int, 20>> spt(N);
for (int i = 0; i < N; i++) {
spt[i][0] = a[i];
}
for (int j = 1; j < 20; j++) {
for (int l = 0, r = 1 << j - 1; r < N; l++, r++) {
spt[l][j] = max(spt[l][j - 1], spt[r][j - 1]);
}
}
auto query = [&](int l, int r) -> int {
if (l == r) {
return -1;
}
int i = __lg(r - l);
return max(spt[l][i], spt[r - (1 << i)][i]);
};
vector<int> ans(N);
ans[0] = N - 1;
ans[N - 1] = 0;
vector<int> s;
vector<int> z;
for (int i = N - 2; i >= 1; i--) {
while (!s.empty() && b[s.back()] >= b[i]) {
s.pop_back();
z.pop_back();
}
s.push_back(i);
int k = z.size();
for (int j = k - 1; j >= 0; j--) {
if (query(b[s[j]] + 1, b[s[j + 1]] + 1) > s[k]) {
k = z[j];
break;
}
}
z.push_back(k);
ans[i] = query(0, b[s.front()] + 1) > s[z.back()] ? 0 : N - 1;
}
for (int i = 0; i < N; i++) {
cout << ans[i] << ' ';
}
cout << '\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 2ms | 2144 KiB | ||||
4 | Accepted | 3ms | 2272 KiB | ||||
5 | Accepted | 3ms | 2344 KiB | ||||
6 | Accepted | 3ms | 2560 KiB | ||||
7 | Accepted | 3ms | 2908 KiB | ||||
8 | Accepted | 3ms | 3116 KiB | ||||
9 | Accepted | 3ms | 3072 KiB | ||||
10 | Accepted | 3ms | 3196 KiB | ||||
11 | Accepted | 3ms | 3276 KiB | ||||
12 | Accepted | 2ms | 3280 KiB | ||||
subtask3 | 28/28 | ||||||
13 | Accepted | 4ms | 3804 KiB | ||||
14 | Accepted | 3ms | 3896 KiB | ||||
15 | Accepted | 3ms | 3944 KiB | ||||
16 | Accepted | 3ms | 3856 KiB | ||||
17 | Accepted | 3ms | 3856 KiB | ||||
18 | Accepted | 3ms | 4120 KiB | ||||
19 | Accepted | 3ms | 4164 KiB | ||||
20 | Accepted | 3ms | 4448 KiB | ||||
21 | Accepted | 3ms | 4444 KiB | ||||
subtask4 | 35/35 | ||||||
22 | Accepted | 68ms | 41596 KiB | ||||
23 | Accepted | 67ms | 41504 KiB | ||||
24 | Accepted | 67ms | 41532 KiB | ||||
25 | Accepted | 67ms | 41628 KiB | ||||
26 | Accepted | 41ms | 26024 KiB | ||||
27 | Accepted | 63ms | 41784 KiB | ||||
28 | Accepted | 71ms | 41672 KiB | ||||
29 | Accepted | 63ms | 41700 KiB | ||||
30 | Accepted | 61ms | 41696 KiB | ||||
31 | Accepted | 79ms | 41764 KiB | ||||
subtask5 | 25/25 | ||||||
32 | Accepted | 959ms | 380080 KiB | ||||
33 | Accepted | 705ms | 342408 KiB | ||||
34 | Accepted | 796ms | 379968 KiB | ||||
35 | Accepted | 709ms | 342400 KiB | ||||
36 | Accepted | 759ms | 364372 KiB | ||||
37 | Accepted | 894ms | 380280 KiB | ||||
38 | Accepted | 722ms | 372648 KiB | ||||
39 | Accepted | 897ms | 380312 KiB | ||||
40 | Accepted | 744ms | 379896 KiB | ||||
41 | Accepted | 976ms | 378944 KiB | ||||
42 | Accepted | 727ms | 365660 KiB | ||||
43 | Accepted | 745ms | 374316 KiB | ||||
44 | Accepted | 968ms | 378812 KiB | ||||
45 | Accepted | 924ms | 377288 KiB | ||||
46 | Accepted | 916ms | 377260 KiB | ||||
47 | Accepted | 971ms | 378844 KiB | ||||
48 | Accepted | 797ms | 378844 KiB | ||||
49 | Accepted | 972ms | 378832 KiB | ||||
50 | Accepted | 961ms | 378828 KiB |