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 MIKU
#define debug(x...) cout << "[" << #x << "] : ", dout(x)
void dout() { cout << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 200005;
int n, a[MXN];
pii dist[MXN];
vector<int> st[MXN], ST;
map<int, int> M;
void DIST() {
FOR(i, 0, n) dist[i] = mp(a[i], i);
sort(dist, dist + n);
for (int i = 0, j = 0; i < n; i = j) {
while (j < n && dist[i].fs == dist[j].fs) j++;
M[i] = dist[i].fs;
FOR(k, i, j) dist[k].fs = i;
}
FOR(i, 0, n) a[dist[i].sc] = dist[i].fs;
}
void miku() {
cin >> n;
FOR(i, 0, n) cin >> a[i];
DIST();
FOR(i, 0, n) {
if (st[a[i]].size()) {
int lst = st[a[i]].back();
while (ST.back() != lst) {
st[a[ST.back()]].pop_back();
ST.pop_back();
}
}
st[a[i]].push_back(i);
ST.push_back(i);
}
int now = -1, id = 0;
FOR(i, 0, n) {
if (ST[id] == i) {
id++;
now = a[i];
}
cout << M[now] << '\n';
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(iostream::failbit);
miku();
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... |