|
#include <bits/stdc++.h>
#define MAXN 200100
using namespace std;
int n, a[MAXN], l[MAXN], r[MAXN];
vector<int> b;
int main() {
scanf("%d", &n);
a[0] = a[n + 1] = -1, r[0] = 1, l[n + 1] = n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] != a[i - 1]) b.push_back(i);
l[i] = i - 1, r[i] = i + 1;
}
while (r[0] != n + 1) {
vector<int> tmp;
for (int i = 0; i < b.size(); i++) {
printf("%d ", b[i]);
int u = l[b[i]], v = r[b[i]];
r[u] = v, l[v] = u;
if (a[b[i]] != a[u] && a[b[i]] == a[v]) tmp.push_back(v);
}
puts("");
b = tmp;
}
return 0;
}
|
|