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 <iostream>
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define lli long long int
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
//para la deque
#define ai first
#define id second
lli n,a;
map<lli,lli> existe;
deque<pll> pila;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,1,n) {
cin >> a;
if (existe.find(a) == existe.end() || existe[a] == 0) {
pila.push_back({a,i});
existe[a] = 1;
continue;
}
while (pila.back().ai != a) {
existe[pila.back().ai] = 0;
pila.pop_back();
}
pila.pop_back();
pila.push_back({a,i});
}
rep(i,1,n) {
cout << pila.front().ai << "\n";
if (i == pila.front().id) pila.pop_front();
}
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... |