This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
int T=1;
//cin>>T;
for(int dalekofrivia=T; dalekofrivia>0; dalekofrivia--){
int N;
cin>>N;
int color[N];
map<int, int> m;
stack<pair<int, int>> Q;
for(int i=1; i<=N; i++){
int h;
cin>>h;
if(m[h]==0){
m[h]++;
pair<int, int> p(i, h);
Q.push(p);
}else{
while(Q.top().second!=h){
m[Q.top().second]--;
Q.pop();
}
Q.pop();
pair<int, int> p(i, h);
Q.push(p);
}
}
int C = Q.top().second;
Q.pop();
for(int i=N-1; i>=0; i--){
if(Q.empty()){
color[i]=C;
}else if(i>=Q.top().first){
color[i]=C;
}else{
C=Q.top().second;
Q.pop();
color[i]=C;
}
}
for(int u: color) cout<<u<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |