Submission #1270512

#TimeUsernameProblemLanguageResultExecution timeMemory
1270512goulthenStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
202 ms19744 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,a,b) for (int i = a; i >= b; i--)
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back

const int MAXN = 2e5+10;
int a[MAXN],ans[MAXN];

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(nullptr);
	int n;cin >> n;
	map<int,int> mp;
	stack<int> stk;
	rep(i,1,n) cin >> a[i];
	
	rep(i,1,n) {
		if (!mp[a[i]]) {
			stk.push(i);
			mp[a[i]]++;
			continue;
		}
		mp[a[i]]++;

		while (a[stk.top()] != a[i]) {
			mp[a[stk.top()]]--;
			stk.pop();
		}
		stk.push(i);
	}

	while (!stk.empty()) {
		ans[stk.top()] = a[stk.top()];
		stk.pop();
	}

	rep(i,1,n) {
		if (!ans[i]) ans[i] = ans[i-1];
		cout << ans[i] << " \n"[i==n];
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...