Submission #941387

#TimeUsernameProblemLanguageResultExecution timeMemory
941387shoryu386Stone Arranging 2 (JOI23_ho_t1)C++17
35 / 100
52 ms14976 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

main(){
	int n; cin >> n;
	int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x];
	
	stack<int> stk;
	unordered_multiset<int> valInStk;
	
	int res[n];
	for (int x = 0; x < n; x++){
		res[x] = arr[x];

		if (valInStk.find(res[x]) != valInStk.end()){
			vector<int> items;
			
			while (!stk.empty()){
				if ( res[stk.top()] == res[x]){
					break;
				}
				else{
					items.push_back(stk.top());
					valInStk.erase(valInStk.find(res[stk.top()]));
					stk.pop();
				}
			}
			
			for (auto y : items){
				res[y] = res[x];
			}
		}
		
		stk.push(x);
		valInStk.insert(res[x]);
	}
	
	for (int x = 0; x < n; x++) cout << res[x] << '\n';
}

Compilation message (stderr)

Main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...