91342024-02-15 18:27:15111A Barbárcpp17Runtime error 0/100904ms380344 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 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
1Accepted3ms1976 KiB
2Accepted3ms2204 KiB
subtask20/12
3Accepted3ms2316 KiB
4Runtime error3ms2300 KiB
5Runtime error3ms2712 KiB
6Runtime error3ms2728 KiB
7Runtime error3ms2776 KiB
8Runtime error3ms2948 KiB
9Runtime error3ms3332 KiB
10Runtime error3ms3348 KiB
11Runtime error3ms3304 KiB
12Runtime error3ms3436 KiB
subtask30/28
13Runtime error3ms3824 KiB
14Runtime error3ms4212 KiB
15Runtime error3ms4156 KiB
16Runtime error3ms4284 KiB
17Runtime error3ms4464 KiB
18Accepted3ms4424 KiB
19Accepted3ms4384 KiB
20Runtime error3ms4656 KiB
21Runtime error3ms4836 KiB
subtask40/35
22Runtime error68ms41824 KiB
23Runtime error70ms42016 KiB
24Runtime error68ms42000 KiB
25Runtime error70ms42416 KiB
26Runtime error37ms26572 KiB
27Accepted75ms42128 KiB
28Accepted67ms42100 KiB
29Accepted65ms42136 KiB
30Accepted65ms42168 KiB
31Runtime error63ms42004 KiB
subtask50/25
32Runtime error712ms380116 KiB
33Runtime error646ms342552 KiB
34Runtime error731ms380148 KiB
35Runtime error651ms342704 KiB
36Runtime error693ms364568 KiB
37Accepted790ms380344 KiB
38Accepted768ms372464 KiB
39Accepted791ms380180 KiB
40Accepted788ms379888 KiB
41Runtime error737ms378680 KiB
42Runtime error675ms365488 KiB
43Runtime error694ms374416 KiB
44Runtime error721ms378772 KiB
45Runtime error713ms377256 KiB
46Runtime error712ms377384 KiB
47Runtime error736ms378984 KiB
48Runtime error748ms378636 KiB
49Runtime error904ms378880 KiB
50Runtime error750ms378832 KiB