101632024-03-28 22:10:18111Mágikus sorozatcpp17Accepted 100/100100ms73496 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<int>v(N);
	for(int i=0;i<N;i++){
		cin>>v[i];
	}
	v[0]=1;
	vector<int>w(N);
	vector<set<int>>u(N+1);
	deque<int>s;
	for(int i=0;i<N;i++){
		s.push_back(i);
		while(!s.empty()&&s.front()+v[s.front()]<=i){
			s.pop_front();
		}
		u[i+v[i]].insert(w[v[i]]);
		int x=1;
		while(u[i].count(x))x++;
		w[i]=s.empty()?x:w[i-s.front()];
		cout<<w[i]+1<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted6ms4120 KiB
subtask215/15
3Accepted4ms2784 KiB
4Accepted4ms3136 KiB
5Accepted4ms3220 KiB
subtask315/15
6Accepted3ms2764 KiB
7Accepted3ms2988 KiB
8Accepted3ms3076 KiB
9Accepted3ms3284 KiB
10Accepted3ms3132 KiB
subtask430/30
11Accepted4ms3820 KiB
12Accepted4ms3804 KiB
13Accepted4ms3752 KiB
14Accepted3ms3960 KiB
subtask540/40
15Accepted90ms69216 KiB
16Accepted89ms64536 KiB
17Accepted82ms49980 KiB
18Accepted82ms54160 KiB
19Accepted83ms52144 KiB
20Accepted78ms48120 KiB
21Accepted76ms43668 KiB
22Accepted75ms42756 KiB
23Accepted74ms43300 KiB
24Accepted82ms58448 KiB
25Accepted76ms44028 KiB
26Accepted75ms43408 KiB
27Accepted96ms63684 KiB
28Accepted93ms72180 KiB
29Accepted100ms73496 KiB
30Accepted79ms46856 KiB
31Accepted85ms60748 KiB
32Accepted90ms69200 KiB