Submission #758696

#TimeUsernameProblemLanguageResultExecution timeMemory
758696PoPularPlusPlusStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
256 ms28480 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

bool remender(ll a , ll b){return a%b;}

void solve(){
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++)cin >> arr[i];
	map<int,vector<int>> m;
	int parent[n];
	memset(parent,-1,sizeof parent);
	priority_queue<int> pq;
	for(int i = 0; i < n; i++){
		if(m[arr[i]].size() != 0){
			int pos = m[arr[i]].back();
			while(pq.size() && pq.top() > pos){
				int idx = pq.top();
				pq.pop();
				parent[idx] = i;
				m[arr[idx]].pop_back();
			}
		}
		pq.push(i);
		m[arr[i]].pb(i);
	}
	for(int i = n - 1; i >= 0; i--){
		if(parent[i] == -1)continue;
		arr[i] = arr[parent[i]];
	}
	for(int i = 0; i < n; i++)cout << arr[i] << '\n';
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("deleg.in", "r", stdin);
//freopen("deleg.out", "w", stdout);
	//int t;cin >> t;while(t--)
	solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...