#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
using namespace std;
#define ll long long
bool comp(const pair<int,int> &a,pair<int,int> &vl)
{
return a.second > vl.first;
}
bool scomp(const pair<int,int> &a,pair<int,int> &vl)
{
return a.first >= vl.first;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
int mx = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
mx = max(mx,a[i]);
}
vector<int> ans(n);
if (mx <= 2) {
if (a[0] == 1) {
bool ok = false;
for (int i = n - 1; i >= 0; i--)
{
if (ok) {
ans[i] = 1;
continue;
}
if (a[i] == 1){
ans[i] = 1;
ok = true;
} else {
ans[i] = 2;
}
}
} else {
bool ok = false;
for (int i = n - 1; i >= 0; i--)
{
if (ok) {
ans[i] = 2;
continue;
}
if (a[i] == 2){
ans[i] = 2;
ok = true;
} else {
ans[i] = 1;
}
}
}
} else {
map<int,int> mp;
for (int i = 0; i < n; i++)
{
if (mp.find(a[i]) != mp.end()) {
for (int j = i - 1; j > mp[a[i]]; j--)
{
mp.erase(a[j]);
ans[j] = a[i];
}
for (int j = 0; j < mp[a[i]]; j++)
{
mp[a[j]] = j;
}
mp[a[i]] = i;
ans[i] = a[i];
} else {
mp[a[i]] = i;
ans[i] = a[i];
}
}
}
for (int i = 0; i < n; i++)
{
cout << ans[i] << endl;
}
}
int main() {
int t = 1;
// cin>>t;
while(t--) {
solve();
}
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... |