#include<iostream>
#include<stack>
using namespace std;
const int N=2e5+10;
struct Fruit{
int num;
bool type;
}
f[N];
stack<Fruit> k[N];
int cnt;
bool flag[N];
int main ()
{
int n;
cin >> n;
for (int i=1; i<=n; i++) f[i].num=i;
cin >> f[1].type;
int j=1;
k[j].push(f[1]);
for (int i=2; i<=n; i++)
{
cin >> f[i].type;
if (f[i].type==f[i-1].type) k[j].push(f[i]);
else k[++j].push(f[i]);
}
// cout << j;
cnt=j;
while (cnt>0) {
int pos=0;
int temp=cnt;
cnt=0;
for (int i=1; i<=temp; i++)
{
int s1=k[i].size();
stack<Fruit> t;
for (int a=1; a<=s1; a++) {
t.push(k[i].top());
k[i].pop();
}
Fruit u=t.top();
cout << u.num << " ";
t.pop();
for (int a=1; a<s1; a++) {
k[i].push(t.top());
t.pop();
}
if (k[i].empty()) {
flag[i]=1;
continue;
}
cnt++;
if (pos==0) {
pos=1;
if (i!=1) {
k[pos]=k[i];
int s2=k[i].size();
for (int a=1; a<=s2; a++)
k[i].pop();
}
continue;
}
if (k[i].top().type==k[pos].top().type) {
flag[i]=1;
stack<Fruit> v;
int s3=k[i].size();
for (int a=1; a<=s3; a++) {
v.push(k[i].top());
k[i].pop();
}
for (int a=1; a<=s3; a++) {
k[pos].push(v.top());
v.pop();
}
}
else {
pos++;
if (i!=pos) {
k[pos]=k[i];
int s4=k[i].size();
for (int a=1; a<=s4; a++)
k[i].pop();
}
}
}
cout << endl;
}
return 0;
}
不知道哪里栈溢出了,4个数据点RE,1个数据点WA