This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
const ll maxn=2e5+2;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin>>n;
int a[n];
unordered_map <int,int> mp;
stack<int> st;
int x;
for (int i=0;i<n;++i){
cin>>x;
if (!mp[x]){
st.push(x);
}else{
int cnt=1;
while (st.top()!=x){
++cnt;
--mp[st.top()];
st.pop();
}
while (cnt--){
st.push(x);
++mp[x];
}
--mp[x];
}
++mp[x];
}
vector<int> v;
while (!st.empty()){
v.push_back(st.top());
st.pop();
}
reverse(v.begin(),v.end());
for (int i: v) cout<<i<<" ";
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:15:9: warning: unused variable 'a' [-Wunused-variable]
15 | int a[n];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |