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;
stack <pair <int,int>> s;
vector <int> res;
set <int> aux;
for(int i = 0;i < n;i++){
int x;
cin >> x;
// cout << x << ' ';
if(aux.find(x) != aux.end()){
while(!s.empty()){
pair <int, int> t = s.top();
s.pop();
aux.erase(t.first);
if(t.first == x){
// s.push({x, i});
break;
}
}
}
s.push({x, i});
aux.insert(x);
}
int cl;
for(int i = n-1;i >= 0;i--){
if(s.empty()) s.push({-1, -1});
pair <int, int> t = s.top();
if(t.second == i){
cl = t.first;
s.pop();
}
res.push_back(cl);
}
reverse(res.begin(), res.end());
for(auto x : res){
cout << x << ' ';
}
cout << '\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... |