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;
#ifdef DEBUG
#include "templates/debug.h"
#else
#define debug(...) 0
#endif
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define eb emplace_back
#define pb push_back
#define mt make_tuple
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int) x.size()
using ll = long long;
using ull = unsigned ll;
using lll = __int128_t;
using ulll = __uint128_t;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
template <class T> using mx_pq = priority_queue<T>;
template <class T> using mn_pq = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0x3f3f3f3f;
const ll LINF = (ll) 1e18;
const double DINF = 1.0 / 0.0;
const double pi = acos(-1);
const double EPS = 1e-9;
void solve(int current_case);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
for (int q = 1; q <= t; q++) solve(q);
return 0;
}
void solve(int current_case) {
int n;
cin >> n;
vi a(n + 1);
rep(i, 0, n) cin >> a[i];
map<int, int> last;
vii st;
rep(i, 0, n) {
int prev = last.count(a[i]) ? last[a[i]] : INF;
last[a[i]] = i;
while (!st.empty() && prev < st.back().first) {
last[a[st.back().first]] = st.back().second;
st.pop_back();
}
st.eb(i, prev);
}
vi ans(n);
rep(i, 0, SZ(st) - 1) rep(j, st[i].first, st[i + 1].first) ans[j] = a[st[i].first];
ans[n - 1] = a[n - 1];
for (auto &x : ans) 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... |