提交时间:2021-12-07 19:12:53
运行 ID: 33726
#include <bits/stdc++.h> using namespace std; const int N=2e5+10; inline int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') w*=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } struct node { int l,r,opt; }; int n,t; queue<node> q,temp; vector<int> ans[N]; bool vis[N]; int main() { n=read(); int l=-1,r=-1,last=-1; for(register int i=1; i<=n; i++) { int x=read(); if(x!=last) { if(last!=-1) q.push((node) { l,r,last }); l=i,r=i; } else r++; last=x; } q.push((node) { l, r, last } ); while(!q.empty()) { t++; int last=-1; int l,r; while(!q.empty()) { node now=q.front(); q.pop(); if(now.opt!=last) { if(last!=-1&&l<=r) temp.push((node) { l,r,last }); // cout<<l<<" "<<r<<endl; while(vis[now.l]) now.l++; vis[now.l]=true; ans[t].push_back(now.l),now.l++; l=now.l,r=now.r; } else r=now.r; last=now.opt; } if(l<=r) temp.push((node) { l,r,last }); while(!temp.empty()) { node add=temp.front(); temp.pop(),q.push(add); } } for(register int i=1; i<=t; i++) { for(register int j=0; j<ans[i].size(); j++) printf("%d ",ans[i][j]); putchar('\n'); } return 0; }