91272024-02-15 17:08:03111A Barbárcpp17Wrong answer 0/10039ms4744 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;
	if (N > 1000) {
		return 0;
	}
	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] = upper_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);
		if (b[s.front()] == i) {
			c[i] = N - 1;
			continue;
		}
		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
1Wrong answer39ms2164 KiB
2Wrong answer39ms2344 KiB
subtask20/12
3Wrong answer39ms2548 KiB
4Wrong answer39ms2840 KiB
5Wrong answer39ms2796 KiB
6Wrong answer39ms2764 KiB
7Wrong answer39ms2924 KiB
8Wrong answer39ms2880 KiB
9Wrong answer39ms2844 KiB
10Wrong answer39ms3412 KiB
11Wrong answer39ms3332 KiB
12Wrong answer39ms3668 KiB
subtask30/28
13Wrong answer39ms3568 KiB
14Wrong answer39ms3696 KiB
15Wrong answer39ms3588 KiB
16Wrong answer39ms3844 KiB
17Wrong answer39ms3800 KiB
18Wrong answer39ms3752 KiB
19Wrong answer39ms3780 KiB
20Wrong answer39ms3748 KiB
21Wrong answer39ms3752 KiB
subtask40/35
22Wrong answer39ms3712 KiB
23Wrong answer39ms4008 KiB
24Wrong answer39ms4012 KiB
25Wrong answer39ms4304 KiB
26Wrong answer39ms4248 KiB
27Wrong answer39ms4204 KiB
28Wrong answer39ms4352 KiB
29Wrong answer39ms4640 KiB
30Wrong answer39ms4692 KiB
31Wrong answer39ms4700 KiB
subtask50/25
32Wrong answer39ms4744 KiB
33Wrong answer39ms4668 KiB
34Wrong answer39ms4624 KiB
35Wrong answer39ms4516 KiB
36Wrong answer39ms4564 KiB
37Wrong answer39ms4556 KiB
38Wrong answer39ms4556 KiB
39Wrong answer39ms4568 KiB
40Wrong answer39ms4520 KiB
41Wrong answer39ms4560 KiB
42Wrong answer39ms4556 KiB
43Wrong answer39ms4564 KiB
44Wrong answer39ms4608 KiB
45Wrong answer39ms4564 KiB
46Wrong answer39ms4520 KiB
47Wrong answer39ms4520 KiB
48Wrong answer39ms4560 KiB
49Wrong answer39ms4516 KiB
50Wrong answer39ms4668 KiB