#include <bits/stdc++.h>
#define REP(v, i, j) for (int v = i; v != j; v++)
#define FORI(v) for (auto i : v)
#define FORJ(v) for (auto j : v)
#define OUT(v, a) \
FORI(v) \
cout << i << a;
#define OUTS(v, a, b) \
cout << v.size() << a; \
OUT(v, b)
#define in(a, n) \
REP(i, 0, n) \
cin >> a[i];
#define SORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define MEMSET(m) memset(m, -1, sizeof m)
#define pb push_back
#define fi first
#define se second
#define detachIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
bool operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
if(__x.size() != __y.size()) return false;
return std::equal(__x.begin(), __x.end(), __y.begin());
}
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pii, pii> piiii;
const int MOD = 1e9+7;
struct modint {
long long val;
modint() = default;
modint(int _val): val(_val){}
modint operator+(modint b){ return ((this->val + b.val)%MOD); }
modint operator-(modint b){ return ((MOD + this->val - b.val)%MOD); }
modint operator*(modint b){ return ((this->val * b.val)%MOD); }
modint operator^(int a){
if(a==0)return 1;
if(a==1)return *this;
return (((*this)*(*this))^(a>>1))*((*this)^(a&1));
}
};
modint invert(modint a){
return a^(MOD-2);
}
modint operator/(modint a, modint b){
return a*invert(b);
}
map<int,pii> mp;
stack<int> stck;
int main(){
detachIO;
int n;cin>>n;
REP(i,1,n+1){
int a;cin>>a;
if(mp.count(a)){
while(stck.top()!=a)mp.erase(stck.top()),stck.pop();
mp[a].se=i;
} else {
mp[a]={i,i};
stck.push(a);
}
}
vector<int> vec;
while(stck.size()){
REP(x,mp[stck.top()].fi,mp[stck.top()].se+1)vec.pb(stck.top());
stck.pop();
}
REV(vec);
FORI(vec)cout<<i<<'\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... |