91392024-02-15 19:06:22111A Barbárcpp17Wrong answer 12/1001.064s380740 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 (j + 1 < s.size() && query(b[s[j]] + 1, b[s[j + 1]] + 1) < y) {
				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
1Accepted3ms1824 KiB
2Accepted3ms2064 KiB
subtask212/12
3Accepted3ms2276 KiB
4Accepted3ms2512 KiB
5Accepted3ms2668 KiB
6Accepted3ms3032 KiB
7Accepted3ms3220 KiB
8Accepted3ms3308 KiB
9Accepted3ms3276 KiB
10Accepted3ms3276 KiB
11Accepted3ms3492 KiB
12Accepted3ms3492 KiB
subtask30/28
13Accepted3ms4096 KiB
14Accepted3ms4236 KiB
15Accepted3ms4412 KiB
16Accepted3ms4628 KiB
17Accepted3ms4840 KiB
18Accepted3ms4704 KiB
19Accepted3ms4700 KiB
20Wrong answer3ms4700 KiB
21Wrong answer3ms4728 KiB
subtask40/35
22Wrong answer72ms41852 KiB
23Wrong answer71ms41860 KiB
24Wrong answer74ms41884 KiB
25Wrong answer71ms42092 KiB
26Wrong answer41ms26292 KiB
27Accepted67ms42108 KiB
28Accepted75ms42356 KiB
29Accepted67ms42424 KiB
30Accepted65ms42464 KiB
31Wrong answer75ms42276 KiB
subtask50/25
32Wrong answer912ms380180 KiB
33Wrong answer765ms342636 KiB
34Time limit exceeded1.036s380404 KiB
35Wrong answer777ms342984 KiB
36Wrong answer814ms365096 KiB
37Accepted961ms380740 KiB
38Accepted781ms372896 KiB
39Accepted963ms380580 KiB
40Accepted967ms380400 KiB
41Wrong answer869ms379172 KiB
42Accepted944ms365944 KiB
43Accepted820ms374600 KiB
44Time limit exceeded1.011s379140 KiB
45Accepted837ms377740 KiB
46Accepted987ms377616 KiB
47Accepted916ms379160 KiB
48Accepted912ms379092 KiB
49Time limit exceeded1.064s191540 KiB
50Accepted935ms379060 KiB