This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC target("abm")
// #pragma GCC optimize("03,unroll-loops")
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("bmi,bmi2,lzcnt,popcnt")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define put(a) cout << a << "\n"
#define put_2(a, b) cout << a << " " << b << "\n"
#define put_3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define put_4(a, b, c, x) cout << a << " " << b << " " << c << " " << x << "\n"
#define put_5(a, b, c, x, y) cout << a << " " << b << " " << c << " " << x << " " << y << "\n";
#define put_6(a, b, c, x, y, z) cout << a << " " << b << " " << c << " " << x << " " << y << " " << z << "\n";
#define put_fix(a, n) cout << fixed << setprecision(n) << a << "\n"
#define ll long long
#define ldb long double
#define db double
#define sqr(x) (x*x)
#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define fdto(i, b, a) for (int i = b; i >= a; --i)
#define sz(a) (int) (a.size())
#define di deque <int>
#define vi vector <int>
#define vl vector <long long>
#define pii pair <int, int>
#define vii vector <int, int>
#define vpii vector<pair<int, int>>
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define oo 1000000007
#define OO 1000000000000000007
#define eps 0.0000000001
#define mod
#define maxN 200005
#define maxM 10000005
using namespace std;
int n, a[maxN];
void sub_1() {
for (int i = 2; i <= n; ++i) {
int pos = 0;
for (int j = i-1; j >= 1; --j) {
if (a[j] == a[i]) {
pos = j;
break;
}
}
if (pos) {
for (int j = pos+1; j <= i-1; ++j) a[j] = a[i];
}
}
for (int i = 1; i <= n; ++i) cout << a[i] << "\n";
}
struct data {
int l, r, val;
data() {
l = 0; r = 0; val = 0;
}
data(int _l, int _r, int _val) {
l = _l; r = _r; val = _val;
}
};
int mx_pos_val[5];
void sub_2() {
vector<data> vec;
mx_pos_val[a[1]] = 1;
for (int i = 2; i <= n; ++i) {
if (a[i] == a[mx_pos_val[a[i]]]) {
vec.push_back({mx_pos_val[a[i]], i, a[i]});
mx_pos_val[a[i]] = i;
}
}
for (int ivec = 0; ivec < (int) vec.size(); ++ivec) {
for (int i = vec[ivec].l; i <= vec[ivec].r; ++i) a[i] = vec[ivec].val;
}
for (int i = 1; i <= n; ++i) cout << a[i] << "\n";
}
int main () {
// #ifndef ONLINE_JUDGE
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
// #endif // ONLINE_JUDGE
FAST;
cin >> n;
bool ok_o = false;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] != 1 && a[2] != 2) ok_o = true;
}
if (n <= 10000) sub_1();
else if (!ok_o) sub_2();
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... |