#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false
const int MAXN = 200 * 1000;
int co[MAXN];
map<int, int> ile;
vector<pii> v;
int main () {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, a;
cin >> n;
for (int i = 0; i < n; i ++) {
cin >> a;
if (ile[a] == 0) {
ile[a] ++;
v.pb({a, i});
continue;
}
while (v.back().st != a) {
ile[v.back().st] --;
v.pop_back();
}
ile[a] ++;
v.pb({a, i});
}
v.pb({a, n});
/*for (auto x : v) {
cout << x.st << " " << x.nd << "\n";
}*/
for (int i = 0; i < n; i ++) {
int p = 0, k = int(v.size()) - 1, wyn = 0;
while (p <= k) {
int sr = (p + k)/ 2;
if (v[sr].nd > i) {
wyn = sr;
k = sr - 1;
} else {
p = sr + 1;
}
}
wyn --;
cout << v[wyn].st << "\n";
}
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... |