# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1176136 | chikien2009 | Stone Arranging 2 (JOI23_ho_t1) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
void setup()
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int n, a[200000], b[200000];
deque<int> pos;
map<int, int> num;
int main()
{
setup();
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> a[i];
while (num[a[i]] && !pos.empty() && a[pos.back()] != a[i])
{
num[a[pos.back()]]--;
pos.pop_back();
}
b[i] = (pos.empty() ? -1 : pos.back());
pos.push_back(i);
num[a[i]]++;
}
for (int i = n - 1; i >= 0;)
{
for (int j = i; j > b[i];--j)
{
a[j] = a[i];
}
i = b[i];
}
for (int i = 0; i < n; ++i)
{
cout << a[i] << "\n";
}
return 0;
}