TLE#8#9
P7912
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int n;
int a[N];
queue<int>p[2][100001];
int tot[2];
int main()
{
a[0]=-1;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
if(a[i]!=a[i-1])
{
tot[a[i]]++;
}
p[a[i]][tot[a[i]]].push(i);
}
while(n)
{
bool flag=true;
int str=1,now=a[1],last=0,k=0;
while(str<=tot[now])
{
if(p[now][str].empty())
{
if(flag)
{
int tmp=last;
last=str;
str=tmp+1;
now^=1;
}
else
{
str++;
k++;
}
}
else
{
flag=false;
printf("%d ",p[now][str].front());
p[now][str].pop();
now^=1;
int tmp=last;
last=str;
str=tmp+k+1;
k=0;
n--;
}
}
printf("\n");
}
return 0;
}