91432024-02-15 20:02:05111A Barbárcpp17Accepted 100/100976ms380312 KiB
#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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2056 KiB
subtask212/12
3Accepted2ms2144 KiB
4Accepted3ms2272 KiB
5Accepted3ms2344 KiB
6Accepted3ms2560 KiB
7Accepted3ms2908 KiB
8Accepted3ms3116 KiB
9Accepted3ms3072 KiB
10Accepted3ms3196 KiB
11Accepted3ms3276 KiB
12Accepted2ms3280 KiB
subtask328/28
13Accepted4ms3804 KiB
14Accepted3ms3896 KiB
15Accepted3ms3944 KiB
16Accepted3ms3856 KiB
17Accepted3ms3856 KiB
18Accepted3ms4120 KiB
19Accepted3ms4164 KiB
20Accepted3ms4448 KiB
21Accepted3ms4444 KiB
subtask435/35
22Accepted68ms41596 KiB
23Accepted67ms41504 KiB
24Accepted67ms41532 KiB
25Accepted67ms41628 KiB
26Accepted41ms26024 KiB
27Accepted63ms41784 KiB
28Accepted71ms41672 KiB
29Accepted63ms41700 KiB
30Accepted61ms41696 KiB
31Accepted79ms41764 KiB
subtask525/25
32Accepted959ms380080 KiB
33Accepted705ms342408 KiB
34Accepted796ms379968 KiB
35Accepted709ms342400 KiB
36Accepted759ms364372 KiB
37Accepted894ms380280 KiB
38Accepted722ms372648 KiB
39Accepted897ms380312 KiB
40Accepted744ms379896 KiB
41Accepted976ms378944 KiB
42Accepted727ms365660 KiB
43Accepted745ms374316 KiB
44Accepted968ms378812 KiB
45Accepted924ms377288 KiB
46Accepted916ms377260 KiB
47Accepted971ms378844 KiB
48Accepted797ms378844 KiB
49Accepted972ms378832 KiB
50Accepted961ms378828 KiB