#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;
const ll oo = 1e18;
bool START;
int n, a[N], ans[N];
vector<int> arr, pos[N];
struct node {
int l, r, c;
node(int l_, int r_, int c_) : l(l_), r(r_), c(c_) {}
};
vector<node> upd;
inline void solve() {
sort(vall(arr));
arr.erase(unique(vall(arr)), arr.end());
for (int i = 1; i <= n; ++i) {
a[i] = lower_bound(vall(arr), a[i]) - arr.begin();
pos[a[i]].pb(i);
}
int i = 1;
while(i <= n) {
auto it = upper_bound(vall(pos[a[i]]), i);
if (it == pos[a[i]].end()) {
upd.pb(node(i, i, arr[a[i]]));
++i;
} else {
upd.pb(node(i, *it - 1, arr[a[i]]));
i = *it;
}
}
for (auto [l, r, color] : upd) for (int i = l; i <= r; ++i) ans[i] = color;
for (int i = 1; i <= n; ++i) cout << ans[i] << endl;
}
inline void input() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
arr.pb(a[i]);
}
return solve();
}
bool END;
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(task ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(task ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |