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;
using ll = long long;
#define fi first
#define si second
#define ar array
#define pb push_back
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
typedef vector<int> vi;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 200010;
int n, a[N], ans[N], jmp[N];
map<int,int> l;
vector<pi> rr;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = n; i >= 1; --i) {
if (l[a[i]]) jmp[i] = l[a[i]];
l[a[i]] = i;
}
int lim = -1;
for (int i = 1; i <= n; ++i) {
if (lim != -1 && i < lim) continue;
if (jmp[i]) {
lim = jmp[i];
rr.pb({i, lim});
}
}
for (auto [s,e]: rr) {
for (int i = s; i <= e; ++i) ans[i] = a[s];
}
for (int i = 1; i <= n; ++i) {
if (!ans[i]) ans[i] = a[i];
cout << ans[i] << '\n';
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:40:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for (auto [s,e]: rr) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |