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 <iostream>
#include <vector>
#include <utility>
#include <sstream>
#include <climits>
#include <cstring>
#include <map>
#define ll long long
#define ld long double
using namespace std;
const ll mod = 1e9 + 7;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
void solve()
{
int n;
cin >> n;
vi color(n);
map<int, int> last_idx;
for (int i = 0; i < n; i++)
{
cin >> color[i];
last_idx[color[i]] = i;
}
for (int i = 0; i < n; i++)
{
if (last_idx.find(color[i]) == last_idx.end())
continue;
int last_i = last_idx[color[i]];
for (int j = i; j <= last_i; j++)
{
color[j] = color[i];
}
i = last_i;
}
for (int i = 0; i < n; i++)
{
cout << color[i] << "\n";
}
}
int main()
{
// freopen("input_text", "r", stdin);
// freopen("output_text", "w", stdout);
// ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t-- > 0)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |