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;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 2e5 + 5;
int n, a[NMAX], cnt[NMAX];
vector<int> ans;
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
stack<int> st;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(cnt[a[i]]){
while(a[st.top()] != a[i]) cnt[a[st.top()]]--, st.pop();
}
else st.emplace(i), cnt[a[i]]++;
}
for(int i = n; i; i--){
ans.emplace_back(a[st.top()]);
if(st.top() == i) st.pop();
}
reverse(all(ans));
for(int& x : ans) cout << x << '\n';
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... |