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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <stack>
#include <set>
typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9;
int n;
int a[MAXN];
std::set <int> wasThere;
std::vector <std::pair <int,int>> st;
std::stack <int> output;
void solve()
{
for (int i = 1 ; i <= n ; ++i)
{
if (!wasThere.count(a[i]))
{
wasThere.insert(a[i]);
st.push_back({i, a[i]});
} else
{
while (st.back().second != a[i])
{
wasThere.erase(wasThere.find(st.back().second));
st.pop_back();
}
}
}
int ptr = n;
while (!st.empty())
{
while (ptr >= st.back().first)
{
output.push(st.back().second);
ptr--;
}
st.pop_back();
}
while (!output.empty())
{
std::cout << output.top() << '\n';
output.pop();
}
}
void input()
{
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
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... |