Code
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
struct node{
int be,ed,num;
};
queue<node>q,q2;
int main(){
int n,a[maxn],i,cnt=1;
bool flag=false;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
a[n+1]=!a[n];
for(i=2;i<=n+1;i++) if(a[i]!=a[i-1]) q.push((node){cnt,i-1,a[i-1]}),cnt=i;
while(!q.empty()){
int len=q.size(),pre=3;
while(len--){
node a=q.front();
q.pop();
if(a.num==pre){
q.push(a);
}
else{
printf("%d ",a.be);
a.be++;
if(a.be<=a.ed) q.push(a);
pre=a.num;
}
}
printf("\n");
}
}
时间复杂度因该是对的啊