제출 #1164129

#제출 시각아이디문제언어결과실행 시간메모리
1164129akacool445kStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
143 ms16528 KiB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define int long long
#define pint pair<int, int>
#define vint vector<pair<int, int>>
const int mod = 1e9 + 7;
const int shrek = 5e5 + 5;
const int say = INT_MAX / 2;
const int gex = INT_MIN / 2;
const long long oo = 1e18;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	map<int, pint> mp;
	for(int i = 0; i < n; i++) {
		if(mp.find(a[i]) == mp.end()) {
			mp.insert({a[i], {i, i}});
		} else {
			mp[a[i]].ss = max(mp[a[i]].ss, i);
		}
	}
	int i = 0;
	while(i < n) {
		int j = mp[a[i]].ss;
		for(int k = i; k < j; k++) a[k] = a[i];
		i = j + 1;

	}
	for(int i = 0; i < n; i++) {
		cout << a[i] << '\n';
	}
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...