91352024-02-15 18:28:51111A Barbárcpp17Wrong answer 40/1001.05s380220 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 y = query(b[s.front()] + 1, b[s[j]] + 1);
			if (query(b[s[j]] + 1, b[s.back()] + 1) <= s.back() && y > s.back()) {
				continue;
			}
			if (y <= 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
2Accepted3ms2056 KiB
subtask212/12
3Accepted3ms2268 KiB
4Accepted3ms2500 KiB
5Accepted3ms2860 KiB
6Accepted3ms2992 KiB
7Accepted3ms3076 KiB
8Accepted3ms3204 KiB
9Accepted3ms3412 KiB
10Accepted3ms3500 KiB
11Accepted3ms3584 KiB
12Accepted3ms3408 KiB
subtask328/28
13Accepted3ms3764 KiB
14Accepted3ms3908 KiB
15Accepted3ms4064 KiB
16Accepted3ms4292 KiB
17Accepted3ms4584 KiB
18Accepted3ms4608 KiB
19Accepted3ms4616 KiB
20Accepted3ms4648 KiB
21Accepted3ms4644 KiB
subtask40/35
22Accepted78ms41752 KiB
23Wrong answer76ms41992 KiB
24Accepted68ms42044 KiB
25Accepted68ms42048 KiB
26Wrong answer37ms26308 KiB
27Accepted64ms42016 KiB
28Accepted63ms41992 KiB
29Accepted63ms41924 KiB
30Accepted63ms42048 KiB
31Accepted71ms41732 KiB
subtask50/25
32Wrong answer848ms379716 KiB
33Accepted717ms342136 KiB
34Wrong answer805ms379672 KiB
35Wrong answer754ms342332 KiB
36Wrong answer765ms364384 KiB
37Accepted740ms380176 KiB
38Accepted736ms372520 KiB
39Accepted745ms380220 KiB
40Accepted745ms379892 KiB
41Wrong answer814ms378636 KiB
42Accepted739ms365424 KiB
43Accepted759ms374136 KiB
44Wrong answer805ms378672 KiB
45Accepted773ms377144 KiB
46Wrong answer933ms377208 KiB
47Accepted851ms378736 KiB
48Time limit exceeded1.019s378892 KiB
49Accepted874ms378656 KiB
50Time limit exceeded1.05s191596 KiB