91252024-02-15 16:58:56111A Barbárcpp17Wrong answer 12/1001.082s42796 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;
//			}
//		}
//	}
	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();
	}
//	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, N - 1, a[i], N);
//	}
//	for (int i = 1; i <= N - 2; i++) {
//		int j = min_element(b.begin() + i, b.end() - 1) - b.begin();
//		int ok = 0;
//		for (int k = 1; k <= b[j]; k++) {
//			ok |= a[k] >= j;
//		}
//		int x = ok ? 0 :N-1;
//		if(ans[i]!=x){
//			cout << i<<" "<<!ans[i] <<  " "<<ok<<endl;
//			exit(2);
//		}
//	}
	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);
		int x = *max_element(a.begin(), a.begin() + b[s.front()] + 1);
		if (x > s.front()) {
			c[i] = N - 1;
			continue;
		}
		for (int j = 1; j < s.size(); j++) {
			if (*max_element(a.begin() + b[s.front()] + 1, a.begin() + b[s[j]] + 1) <= s[j] && x > s[j]) {
				c[i] = N - 1;
				break;
			}
		}
	}
	for (int i = 1; i <= N - 2; i++) {
		int x = c[i] == N - 1 ? 0 : N - 1;
//		if(ans[i]!=x){
//			cout<<i<<" "<<!ans[i]<<" "<<!!c[i]<<endl;
//			exit(1);
//		}
		ans[i] = x;
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Accepted3ms1868 KiB
subtask212/12
3Accepted3ms2080 KiB
4Accepted3ms2288 KiB
5Accepted3ms2504 KiB
6Accepted3ms2720 KiB
7Accepted3ms2936 KiB
8Accepted3ms2992 KiB
9Accepted3ms3124 KiB
10Accepted3ms3212 KiB
11Accepted3ms3336 KiB
12Accepted3ms3420 KiB
subtask30/28
13Accepted3ms3448 KiB
14Accepted3ms3456 KiB
15Accepted3ms3464 KiB
16Accepted3ms3524 KiB
17Accepted3ms3520 KiB
18Accepted3ms3520 KiB
19Accepted3ms3612 KiB
20Wrong answer3ms3572 KiB
21Accepted3ms3576 KiB
subtask40/35
22Time limit exceeded1.049s6464 KiB
23Time limit exceeded1.07s6468 KiB
24Time limit exceeded1.065s6656 KiB
25Time limit exceeded1.074s6532 KiB
26Time limit exceeded1.062s5072 KiB
27Time limit exceeded1.07s6824 KiB
28Time limit exceeded1.062s7124 KiB
29Time limit exceeded1.07s7120 KiB
30Time limit exceeded1.049s7116 KiB
31Time limit exceeded1.082s7044 KiB
subtask50/25
32Time limit exceeded1.072s42532 KiB
33Time limit exceeded1.072s38748 KiB
34Time limit exceeded1.078s42564 KiB
35Time limit exceeded1.067s38864 KiB
36Time limit exceeded1.057s40812 KiB
37Time limit exceeded1.049s42428 KiB
38Time limit exceeded1.057s41532 KiB
39Time limit exceeded1.078s42492 KiB
40Time limit exceeded1.065s42512 KiB
41Time limit exceeded1.052s42368 KiB
42Time limit exceeded1.059s41056 KiB
43Time limit exceeded1.062s41976 KiB
44Time limit exceeded1.067s42328 KiB
45Time limit exceeded1.059s42112 KiB
46Time limit exceeded1.075s42036 KiB
47Time limit exceeded1.07s42552 KiB
48Time limit exceeded1.078s42492 KiB
49Time limit exceeded1.07s42672 KiB
50Time limit exceeded1.077s42796 KiB