91242024-02-15 13:59:41111A Barbárcpp17Time limit exceeded 40/1001.1s97848 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int random(int l, int h) {
	static mt19937 gen;
	return uniform_int_distribution<int>(l, h)(gen);
}

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 = 1000;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		v[i] = random(1, 1000000000);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	vector<int> ans(N);
	ans[0] = N - 1;
	ans[N - 1] = 0;
//	for (int i = 1; i < N - 1; i++) {
//		list<int> l(v.begin(), v.end());
//		auto t = next(l.begin(), i);
//		while (true) {
//			if (*t - *prev(t) <= *next(t) - *t) {
//				t = prev(l.erase(t));
//			}
//			else {
//				t = l.erase(t);
//			}
//			if (t == l.begin()) {
//				ans[i] = N - 1;
//				break;
//			}
//			if (t == prev(l.end())) {
//				ans[i] = 0;
//				break;
//			}
//		}
//	}
//	for (int i = 0; i < N; i++) {
//		cout << setw(3) << ans[i] << ' ';
//	}
//	cout << '\n';
	vector<int> a(N);
	vector<int> b(N);
	vector<int> c(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();
		c[i] = i;
	}
	vector<vector<int>> rb(N);
	for (int i = 0; i <= N - 1; i++) {
		rb[b[i]].push_back(i);
	}
	auto update_greater = [&](int l, int r, int x, int y) {
		while (r >= l) {
			if (c[r] > x) {
				c[r] = y;
			}
			r--;
		}
	};
	auto update_less = [&](int l, int r, int x, int y) {
		while (r >= l) {
			if (c[r] < x) {
				c[r] = y;
			}
			r--;
		}
	};
	for (int i = N - 1; i >= 0; i--) {
		for (int j : rb[i]) {
			update_greater(0, j, j, j);
		}
		update_less(0, a[i] - 1, a[i], N - 1);
	}
	for (int i = 1; i < N - 1; i++) {
		ans[i] = (c[i] == N - 1) ? 0 : N - 1;
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1836 KiB
2Accepted3ms2048 KiB
subtask212/12
3Accepted3ms2148 KiB
4Accepted3ms2336 KiB
5Accepted3ms2548 KiB
6Accepted3ms2784 KiB
7Accepted3ms2864 KiB
8Accepted3ms2848 KiB
9Accepted3ms3204 KiB
10Accepted3ms3124 KiB
11Accepted3ms3336 KiB
12Accepted3ms3424 KiB
subtask328/28
13Accepted4ms3828 KiB
14Accepted4ms3844 KiB
15Accepted4ms4184 KiB
16Accepted4ms4196 KiB
17Accepted4ms4204 KiB
18Accepted4ms4204 KiB
19Accepted4ms4240 KiB
20Accepted4ms4360 KiB
21Accepted4ms4364 KiB
subtask40/35
22Time limit exceeded1.1s11516 KiB
23Time limit exceeded1.078s11640 KiB
24Time limit exceeded1.062s11620 KiB
25Time limit exceeded1.08s11656 KiB
26Time limit exceeded1.065s8144 KiB
27Time limit exceeded1.07s12800 KiB
28Time limit exceeded1.077s13016 KiB
29Time limit exceeded1.059s12988 KiB
30Time limit exceeded1.07s12968 KiB
31Time limit exceeded1.082s11756 KiB
subtask50/25
32Time limit exceeded1.041s86020 KiB
33Time limit exceeded1.062s77624 KiB
34Time limit exceeded1.047s86012 KiB
35Time limit exceeded1.077s77896 KiB
36Time limit exceeded1.088s82548 KiB
37Time limit exceeded1.064s97840 KiB
38Time limit exceeded1.065s95952 KiB
39Time limit exceeded1.085s97848 KiB
40Time limit exceeded1.078s97832 KiB
41Time limit exceeded1.069s85880 KiB
42Time limit exceeded1.08s93984 KiB
43Time limit exceeded1.065s96096 KiB
44Time limit exceeded1.072s82708 KiB
45Time limit exceeded1.057s95316 KiB
46Time limit exceeded1.055s95392 KiB
47Time limit exceeded1.059s97732 KiB
48Time limit exceeded1.078s97736 KiB
49Time limit exceeded1.08s97656 KiB
50Time limit exceeded1.052s97796 KiB