You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct Node {
int l, r, v;
};
int w[N];
bool st[N];
int n;
queue<Node> q, p;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
w[n + 1] = 2;
for (int i = 1, start = 1; i <= n; i++)
if (w[i] != w[i + 1]) {
q.push({start, i, w[i]});
start = i + 1;
}
int cnt = 0;
while (cnt < n) {
while (q.size()) {
auto a = q.front();
q.pop();
while (st[a.l] && a.l <= a.r) a.l++;
if (a.l > a.r) continue;
printf("%d ", a.l);
cnt++;
st[a.l] = true;
a.l++;
if (a.l > a.r) continue;
p.push(a);
}
while (p.size()) {
auto a = p.front();
p.pop();
while (p.size()) {
auto b = p.front();
if (b.v == a.v) {
a.r = b.r;
p.pop();
} else
break;
}
q.push(a);
}
puts("");
}
return 0;
}