91322024-02-15 18:03:36111A Barbárcpp17Wrong answer 40/10041ms5028 KiB
#pragma GCC optimize("O2")

#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 = 20;
	cin >> N;
	if (N > 1000) {
		return 0;
	}
	vector<int> v(N);
	for(int j=0;j<5;j++){
	for (int i = 0; i < N; i++) {
		v[i] = random(1, N*5);
	}
	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;
		}
		if(0&&i==632){
			cout<<x<<endl;
			cout<<s.size()<<endl;
			for(int j:s)cout<<j<<" ";cout<<endl;
			for(int j:s)cout<<b[j]<<" ";cout<<endl;

			cout<<endl;
			int h = i;
			for (int j = i; j > 0; j--) {
				if (a[j] > h) {
					cout << "at " << j << " " << a[j]<<endl;
					cout<<"from " << h << " ";
					while (h < N && b[h] >= j) {
						h++;
					}
					cout<<"to " << h << " blocker " << b[h]<< endl;
				}
			}
		}
		for (int j = 1; j < s.size(); j++) {
			int y = *max_element(a.begin() + b[s.front()] + 1, a.begin() + b[s[j]] + 1);
			if (j + 1 < s.size() && *max_element(a.begin() + b[s[j]] + 1, a.begin() + b[s[j + 1]] + 1) <= s[j + 1] && y > s[j + 1]) {
				continue;
			}
			if (y <= 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(!!c[i]);
		}
		ans[i] = x;
	}
//	main();
	for (int i = 0; i < N; i++) {
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2064 KiB
subtask212/12
3Accepted3ms2240 KiB
4Accepted3ms2456 KiB
5Accepted3ms2808 KiB
6Accepted3ms2888 KiB
7Accepted3ms3124 KiB
8Accepted3ms3208 KiB
9Accepted3ms3180 KiB
10Accepted3ms3304 KiB
11Accepted3ms3208 KiB
12Accepted3ms3208 KiB
subtask328/28
13Accepted27ms3248 KiB
14Accepted34ms3516 KiB
15Accepted35ms3604 KiB
16Accepted34ms3536 KiB
17Accepted41ms3848 KiB
18Accepted29ms4112 KiB
19Accepted39ms4392 KiB
20Accepted39ms4380 KiB
21Accepted41ms4424 KiB
subtask40/35
22Wrong answer3ms4276 KiB
23Wrong answer3ms4300 KiB
24Wrong answer3ms4340 KiB
25Wrong answer2ms4344 KiB
26Wrong answer3ms4568 KiB
27Wrong answer3ms4564 KiB
28Wrong answer3ms4704 KiB
29Wrong answer2ms4776 KiB
30Wrong answer3ms4872 KiB
31Wrong answer2ms4784 KiB
subtask50/25
32Wrong answer3ms4776 KiB
33Wrong answer3ms4900 KiB
34Wrong answer3ms4772 KiB
35Wrong answer2ms4776 KiB
36Wrong answer3ms4784 KiB
37Wrong answer3ms4780 KiB
38Wrong answer3ms4780 KiB
39Wrong answer3ms4784 KiB
40Wrong answer3ms4780 KiB
41Wrong answer3ms4784 KiB
42Wrong answer3ms4880 KiB
43Wrong answer3ms4876 KiB
44Wrong answer3ms4976 KiB
45Wrong answer3ms4784 KiB
46Wrong answer3ms4784 KiB
47Wrong answer3ms4880 KiB
48Wrong answer3ms4880 KiB
49Wrong answer3ms5028 KiB
50Wrong answer3ms4880 KiB