91422024-02-15 19:50:34111A Barbárcpp17Time limit exceeded 75/1001.014s379716 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;
	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);
		int k = s.size() - 1;
		for (int j = s.size() - 2; j >= 0; j--) {
			if (query(b[s[j]] + 1, b[s[j + 1]] + 1) > s[k]) {
				k = j;
			}
		}
		if (x > s[k]) {
			ans[i] = 0;
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2016 KiB
subtask212/12
3Accepted3ms2232 KiB
4Accepted3ms2468 KiB
5Accepted3ms2668 KiB
6Accepted3ms2792 KiB
7Accepted3ms2960 KiB
8Accepted3ms3168 KiB
9Accepted3ms3244 KiB
10Accepted3ms3248 KiB
11Accepted3ms3260 KiB
12Accepted3ms3328 KiB
subtask328/28
13Accepted3ms3940 KiB
14Accepted3ms3936 KiB
15Accepted3ms3824 KiB
16Accepted3ms4128 KiB
17Accepted3ms3972 KiB
18Accepted3ms3996 KiB
19Accepted3ms4040 KiB
20Accepted3ms4012 KiB
21Accepted3ms4012 KiB
subtask435/35
22Accepted68ms41232 KiB
23Accepted67ms41200 KiB
24Accepted67ms41256 KiB
25Accepted67ms41460 KiB
26Accepted37ms25592 KiB
27Accepted61ms41400 KiB
28Accepted71ms41604 KiB
29Accepted64ms41600 KiB
30Accepted61ms41484 KiB
31Accepted76ms41328 KiB
subtask50/25
32Accepted782ms379256 KiB
33Accepted853ms341728 KiB
34Accepted800ms379356 KiB
35Accepted707ms341928 KiB
36Accepted748ms363860 KiB
37Accepted731ms379712 KiB
38Accepted883ms371832 KiB
39Accepted734ms379528 KiB
40Accepted906ms379716 KiB
41Accepted802ms378216 KiB
42Accepted736ms365012 KiB
43Accepted754ms373640 KiB
44Accepted968ms378324 KiB
45Accepted930ms377040 KiB
46Accepted772ms376944 KiB
47Accepted828ms378556 KiB
48Time limit exceeded1.006s378656 KiB
49Accepted843ms378504 KiB
50Time limit exceeded1.014s378508 KiB