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>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n;
cin >> n;
map<int, pii> seg;
vector<int> vseg;
Loop (i,0,n) {
int x;
cin >> x;
auto it = seg.find(x);
if (it == seg.end()) {
seg[x] = {i, i + 1};
vseg.push_back(x);
} else {
seg[x].second = i + 1;
while (vseg.back() != x) {
seg.erase(vseg.back());
vseg.pop_back();
}
}
}
for (auto x : vseg) {
auto [l, r] = seg[x];
// cerr << x << ' ' << l << ' ' << r << '\n';
Loop (_,0,r-l)
cout << x << '\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... |