提交时间:2021-12-10 13:03:57
运行 ID: 34160
#include <bits/stdc++.h> using namespace std; const int MAXN=200010; int ID[MAXN],L[MAXN], R[MAXN],a[MAXN]= {-1}; int main() { int n,group=0; scanf("%d", &n); for (int i=1; i<=n; ++i) { scanf("%d",&a[i]); L[i]=i-1; R[i]=i+1; if (a[i]!= a[i-1]) ID[group++]=i; } while (group) { int NewGroup=0; for (int i=0;i<group;++i) { printf("%d ",ID[i]); int l=L[ID[i]]; int r=R[ID[i]]; L[r]=l; R[l]=r; if (r!=n+1&&a[ID[i]]==a[r]&&a[r]!=a[l]) ID[NewGroup++]=r; } group=NewGroup; printf("\n"); } return 0; }