#include<bits/stdc++.h>
using namespace std;
int n,a[200005],b[200005],t[200005],hd[200005],hd2[200005],nxt[200005],fa[200005],sum,cnt,c,ttt;
int find(int i) {
if(fa[i]!=i) return fa[i]=find(fa[i]);
return i;
}
void merge(int x,int y) {
x=find(x),y=find(y);
if(x>y) swap(x,y);
fa[x]=y;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]),fa[i]=i;
++cnt;
b[1]=1,hd[1]=1;
for(int i=2;i<=n;++i) {
if(a[i]!=a[i-1]) ++cnt,hd[cnt]=i;
++b[cnt];
}
while(sum<n) {
for(int i=1;i<cnt;++i) printf("%d ",hd[i]),merge(hd[i]-1,hd[i]);
printf("%d\n",hd[cnt]);
merge(hd[cnt]-1,hd[cnt]);
sum+=cnt;
c=0;
ttt=0;
for(int i=1;i<=cnt;++i) {
if(b[i]>1) {
if(b[i-1]>1||c==0||ttt%2==0) ++c,hd2[c]=find(hd[i])+1,t[c]=0;
t[c]+=b[i]-1;
ttt=0;
}
else ++ttt;
}
cnt=c;
for(int i=1;i<=cnt;++i) b[i]=t[i],hd[i]=hd2[i];
}
return 0;
}
|