提交时间:2021-12-09 13:31:44
运行 ID: 34033
#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; cout<<endl; } return 0; }