# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
774754 | vjudge1 | Stone Arranging 2 (JOI23_ho_t1) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #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() {
fto(i, 2, n) {
int pos = 0;
fdto(j, i-1, 1) {
if (a[j] == a[i]) {
pos = j;
break;
}
}
if (pos) fto(j, pos+1, i-1) a[j] = a[i];
}
fto(i, 1, n) put(a[i]);
}
struct data {
int l, r, val;
};
int mx_pos_val[5];
void sub_2() {
vector<data> v;
mx_pos_val[a[1]] = 1;
fto(i, 2, n) {
if (a[i] == a[mx_pos_val[a[i]]]) {
v.pb({mx_pos_val[a[i]], i, a[i]});
mx_pos_val[a[i]] = i;
}
}
fto(iv, 0, sz(v) - 1) {
fto(i, v[iv].l, v[iv].r) {
a[i] = v[iv].val;
}
}
fto(i, 1, n) put(a[i]);
}
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;
fto(i, 1, n) {
cin >> a[i];
if (a[i] != 1 && a[2] != 2) ok_o = true;
}
// sub_2();
if (n <= 10000) sub_1();
else if (!ok_o) sub_2();
return 0;
}