#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
int a[MAX_N + 1], frecv[MAX_N + 1];
unordered_map<int, int> pos;
int main() {
int n, m = 0;
cin >> n;
for ( int i = 1; i <= n; i++ ) {
++m;
cin >> a[m];
frecv[m] = 1;
if ( pos[a[m]] > 0 ) {
int j = m - 1;
frecv[j] += 1;
while ( j > pos[a[m]] ) {
pos[a[j]] = 0;
frecv[pos[a[m]]] += frecv[j];
j--;
}
m = j;
} else
pos[a[m]] = m;
}
for ( int i = 1; i <= m; i++ ) {
for ( int j = 0; j < frecv[i]; j++ )
cout << a[i] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |