提交时间:2021-12-12 22:19:04
运行 ID: 34880
#include <bits/stdc++.h> using namespace std; const int N=2e5+10; struct node { int l,r,opt; }; int n,t; queue<node> q,temp; vector<int> ans[N]; bool vis[N]; int main() { cin>>n; int l=-1,r=-1,last=-1; for(register int i=1; i<=n; i++) { int x; cin>>x; 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 }); 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++) cout<<ans[i][j]<<' '; puts(""); } return 0; }