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(){
int n;
cin>>n;
map<int,int>mp;
stack<pair<int,int> >st;
for(int i=0;i<n;i++){
int a;
cin>>a;
if(mp[a]==0){
st.push({a,1});
mp[a]++;
}else{
int sz=1;
while(st.top().first!=a){
sz+=st.top().second;
mp[st.top().first]-=st.top().second;
st.pop();
}
sz+=st.top().second;
mp[a]-=st.top().second;
st.pop();
st.push({a,sz});
mp[a]+=sz;
}
}
stack<pair<int,int> >st2;
while(!st.empty()){
st2.push(st.top());
st.pop();
}
while(!st2.empty()){
int a=st2.top().first;
int j=st2.top().second;
for(int i=0;i<j;i++){
cout<<a<<"\n";
}
st2.pop();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |