91412024-02-15 19:13:15111A Barbárcpp17Wrong answer 75/1001.062s380388 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);
		if (x > s.front()) {
			ans[i] = 0;
			continue;
		}
		for (int j = 1; j < s.size(); j++) {
			int bad = 0;
			for (int k = j + 1; k < s.size(); k++) {
				if (query(b[s[j]] + 1, b[s[k]] + 1) <= s[k] && query(b[s.front()] + 1, b[s[k - 1]] + 1) > s[k]) {
					bad = 1;
				}
			}
			if (bad) {
				break;
			}
			if (query(b[s.front()] + 1, b[s[j]] + 1) <= s[j] && x > s[j]) {
				ans[i] = 0;
				break;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2052 KiB
subtask212/12
3Accepted3ms2232 KiB
4Accepted3ms2448 KiB
5Accepted3ms2668 KiB
6Accepted3ms2692 KiB
7Accepted3ms2704 KiB
8Accepted3ms2920 KiB
9Accepted3ms3132 KiB
10Accepted3ms3476 KiB
11Accepted3ms3552 KiB
12Accepted3ms3776 KiB
subtask328/28
13Accepted3ms4264 KiB
14Accepted3ms4128 KiB
15Accepted3ms4048 KiB
16Accepted3ms4048 KiB
17Accepted3ms4052 KiB
18Accepted3ms4328 KiB
19Accepted3ms4392 KiB
20Accepted3ms4264 KiB
21Accepted3ms4260 KiB
subtask435/35
22Accepted68ms41496 KiB
23Accepted75ms41416 KiB
24Accepted70ms41408 KiB
25Accepted68ms41628 KiB
26Accepted41ms25808 KiB
27Accepted71ms41620 KiB
28Accepted61ms41608 KiB
29Accepted61ms41892 KiB
30Accepted71ms41988 KiB
31Accepted70ms41800 KiB
subtask50/25
32Accepted957ms379588 KiB
33Accepted855ms342344 KiB
34Accepted801ms379812 KiB
35Wrong answer711ms342388 KiB
36Wrong answer757ms364396 KiB
37Accepted745ms380180 KiB
38Accepted725ms372464 KiB
39Accepted750ms380388 KiB
40Accepted907ms379980 KiB
41Accepted806ms378760 KiB
42Accepted885ms365596 KiB
43Accepted912ms374172 KiB
44Accepted818ms378648 KiB
45Accepted771ms377112 KiB
46Accepted929ms377360 KiB
47Accepted902ms378984 KiB
48Time limit exceeded1.062s191504 KiB
49Time limit exceeded1.001s378936 KiB
50Accepted970ms378872 KiB