81662024-01-12 15:20:04FulopMateTitkos sorozatcpp17Accepted 40/4035ms25688 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> v, ans;
vector<vector<int>> w;

void solve(int l, int r, int mn, int mx, int kov){
	if(l > r)return;
    if(l == r){
        ans[l] = mn;
        return;
    }
	int i = *lower_bound(w[kov].begin(), w[kov].end(), l);
	ans[i] = mx;
	solve(l, i-1, mn, mn+(i-1-l), i);
	solve(i+1, r, mn+(i-1-l)+1, mx-1, kov);
}

/*
5
-1 3 4 -1 -1
*/

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	// ifstream cin("be2.txt");
	cin>>n;
	v.assign(n, 0);
	for(int&i:v){cin>>i;i--;if(i == -2)i = n;}
	w.assign(n+1, {});
	for(int i = 0; i < n; i++){
		w[v[i]].push_back(i);
	}
	ans.assign(n, 0);
	solve(0, n-1, 0, n-1, n);
	for(int i : ans)cout<<i+1<<" ";
	cout<<endl;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1832 KiB
2Accepted0/017ms7620 KiB
3Accepted1/13ms2268 KiB
4Accepted1/13ms2476 KiB
5Accepted2/23ms2692 KiB
6Accepted1/13ms2840 KiB
7Accepted1/13ms3088 KiB
8Accepted2/23ms3260 KiB
9Accepted2/232ms12736 KiB
10Accepted2/232ms12740 KiB
11Accepted2/232ms12896 KiB
12Accepted2/232ms13148 KiB
13Accepted2/234ms13852 KiB
14Accepted2/234ms14660 KiB
15Accepted2/234ms16408 KiB
16Accepted3/334ms17044 KiB
17Accepted3/332ms17612 KiB
18Accepted3/335ms18272 KiB
19Accepted3/335ms19812 KiB
20Accepted3/335ms25688 KiB
21Accepted1/134ms13548 KiB
22Accepted1/132ms13524 KiB
23Accepted1/132ms13316 KiB