Submission #1281753

#TimeUsernameProblemLanguageResultExecution timeMemory
1281753muhammad-ahmadStone Arranging 2 (JOI23_ho_t1)C++20
0 / 100
1 ms712 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

void solve(){
	int n, c = 0; cin >> n;
	int a[n + 1] = {};
	
	map<int, int> val, rev;
	
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		if (val[a[i]]) a[i] = val[a[i]];
		else {
			val[a[i]] = ++c;
			rev[c] = a[i];
			a[i] = val[a[i]];
		}
	}
	
	deque<int> idx[n + 1] = {};
	for (int i = 1; i <= n; i++) idx[a[i]].push_back(i);
	for (int i = 1; i <= n; i++){
		while (idx[a[i]].size() && idx[a[i]].front() <= i) idx[a[i]].pop_front();
		if (idx[a[i]].empty()){
			continue;
			// cout << i << ' ' << 'H' << endl;
		}
		int j = idx[a[i]].front();
		// cout << j << endl;
		for (int k = i; k <= j; k++){
			a[k] = a[i];
		}
		i = j;
	}
	
	for (int i = 1; i <= n; i++) cout << a[i] << ' ';
	cout << endl;
	
	
}

signed main(){
	int tc = 1;
	// cin >> tc;
	while (tc--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...