80分求助
查看原帖
80分求助
749793
chenshixian楼主2024/10/24 08:59
#include<bits/stdc++.h>
using namespace std;
struct P{
	int l,r,z;
};
queue<P>q,p;
int n,a[200010];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		int j=i;
		while(a[j]==a[i]&&j<=n)j++;
		q.push({i,j-1,a[i]});
		i=j-1;
	}
	int c=n;

	while(c){
		int sy=-1;
		while(!q.empty()){
			P v=q.front();
			q.pop();
			if(v.z==sy){
				p.push({v.l,v.r,v.z});
				continue;
			}
			printf("%d ",v.l);
			if(v.l<v.r)p.push({v.l+1,v.r,v.z});
			c--;
			sy=v.z;
		}
		printf("\n");
		while(!p.empty()){
			P v=p.front();
			p.pop();
			q.push(v);
		}
	}
	
	return 0;	
}
2024/10/24 08:59
加载中...