#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 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;
for (int i = N - 2; i >= 1; i--) {
while (!s.empty() && b[s.back()] >= b[i]) {
s.pop_back();
}
s.push_back(i);
ans[i] = N - 1;
int x = query(0, b[s.front()] + 1);
if (x > s.front()) { // jump to end from last blocker
ans[i] = 0;
continue;
}
for (int j = 1; j < s.size(); j++) {
int y = query(b[s.front()] + 1, b[s[j]] + 1);
if (j + 1 < s.size() && query(b[s[j]] + 1, b[s[j + 1]] + 1) <= s[j + 1] && y > s[j + 1]) { // didnt reach blocker s[j]
continue;
}
if (y <= s[j] && x > s[j]) { // jump to end from blocker s[j]
ans[i] = 0;
break;
}
}
}
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 | 1824 KiB | ||||
2 | Accepted | 3ms | 2016 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2252 KiB | ||||
4 | Accepted | 3ms | 2464 KiB | ||||
5 | Accepted | 3ms | 2676 KiB | ||||
6 | Accepted | 3ms | 2880 KiB | ||||
7 | Accepted | 3ms | 2968 KiB | ||||
8 | Accepted | 3ms | 2968 KiB | ||||
9 | Accepted | 3ms | 3228 KiB | ||||
10 | Accepted | 3ms | 3176 KiB | ||||
11 | Accepted | 3ms | 3180 KiB | ||||
12 | Accepted | 3ms | 3308 KiB | ||||
subtask3 | 28/28 | ||||||
13 | Accepted | 3ms | 3656 KiB | ||||
14 | Accepted | 3ms | 3880 KiB | ||||
15 | Accepted | 3ms | 3848 KiB | ||||
16 | Accepted | 3ms | 3756 KiB | ||||
17 | Accepted | 3ms | 3924 KiB | ||||
18 | Accepted | 3ms | 3888 KiB | ||||
19 | Accepted | 3ms | 3896 KiB | ||||
20 | Accepted | 3ms | 3892 KiB | ||||
21 | Accepted | 3ms | 3896 KiB | ||||
subtask4 | 35/35 | ||||||
22 | Accepted | 67ms | 41052 KiB | ||||
23 | Accepted | 67ms | 41016 KiB | ||||
24 | Accepted | 67ms | 41052 KiB | ||||
25 | Accepted | 67ms | 41264 KiB | ||||
26 | Accepted | 37ms | 25560 KiB | ||||
27 | Accepted | 61ms | 41392 KiB | ||||
28 | Accepted | 63ms | 41248 KiB | ||||
29 | Accepted | 61ms | 41268 KiB | ||||
30 | Accepted | 61ms | 41308 KiB | ||||
31 | Accepted | 68ms | 41164 KiB | ||||
subtask5 | 0/25 | ||||||
32 | Accepted | 962ms | 379432 KiB | ||||
33 | Accepted | 708ms | 341724 KiB | ||||
34 | Accepted | 968ms | 379536 KiB | ||||
35 | Wrong answer | 865ms | 341960 KiB | ||||
36 | Wrong answer | 910ms | 363932 KiB | ||||
37 | Accepted | 739ms | 379796 KiB | ||||
38 | Accepted | 727ms | 372028 KiB | ||||
39 | Accepted | 902ms | 379800 KiB | ||||
40 | Accepted | 894ms | 379800 KiB | ||||
41 | Accepted | 970ms | 378580 KiB | ||||
42 | Accepted | 884ms | 365420 KiB | ||||
43 | Accepted | 902ms | 374176 KiB | ||||
44 | Accepted | 955ms | 378832 KiB | ||||
45 | Accepted | 921ms | 377268 KiB | ||||
46 | Accepted | 768ms | 377244 KiB | ||||
47 | Accepted | 847ms | 378856 KiB | ||||
48 | Time limit exceeded | 1.026s | 378804 KiB | ||||
49 | Accepted | 879ms | 378872 KiB | ||||
50 | Time limit exceeded | 1.054s | 191460 KiB |