제출 #857051

#제출 시각아이디문제언어결과실행 시간메모리
857051NotLinuxStone Arranging 2 (JOI23_ho_t1)C++17
35 / 100
28 ms884 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
void solve(){
	int n,sz = 0;
	cin >> n;
	map < int , int > last;
	stack < array < int , 3 > > v;
	while(n--){
		int x;cin >> x;
		if(last.count(x)){
			sz++;
			while(v.size() and (last[x]-1) != (int)v.size()){
				v.pop();
			}
			v.push({x,(v.size() ? v.top()[2] : 0)+1,sz});
		}
		else{
			sz++;
			v.push({x,sz,sz});
		}
		last[x] = v.size();
	}
	vector < array < int , 3 > > vv;
	while(v.size()){
		vv.push_back(v.top());
		v.pop();
	}
	reverse(vv.begin() , vv.end());
	for(auto itr : vv){
		for(int j = 0;j<(itr[2] - itr[1] + 1);j++){
			cout << itr[0] << '\n';
		}
	}
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...