10分,其他全RE
查看原帖
10分,其他全RE
768382
thy80楼主2024/8/19 14:02
#include<bits/stdc++.h>
using namespace std;
const int N=2*1e5+5;
struct node{
	int next;
	int id;
	int sum;
	int pre;
	queue<int> number;
	node(){
		id=2;
		next=0;
		pre=0;
		sum=0;
	}
}a[N];
int cnt=0;
int n;
void get(int x)
{
	a[a[x].next].pre=a[x].pre;
	a[a[x].pre].next=a[x].next; 
}
int main(){
	scanf("%d",&n);
	int x=2;
	a[cnt].next=1;
	for(int i=1;i<=n;i++)
	{
		int s;
		scanf("%d",&s);
		if(s==x)
		{
			a[cnt].sum++;
			a[cnt].number.push(i);
		}
		else
		{
			a[cnt].next=++cnt;
			a[cnt].pre=cnt-1;
			a[cnt].id=s;
			a[cnt].sum=1;
			a[cnt].number.push(i);
		}
		x=s;
	}
	a[cnt].next=0;
//	cout<<a[8].number.back()<<endl;
	int ans=cnt;
	while(ans!=0)
	{
		for(int i=a[0].next;i!=0;)
		{
//			cout<<a[i].sum<<" "<<i<<"-\n";
			a[i].sum--;
			printf("%d ",a[i].number.front());
			a[i].number.pop();
			i=a[i].next;
		}
		for(int i=a[0].next;i!=0;)
		{
			if(a[i].sum<=0)
			{
				ans--;
				get(i);
				if(a[i].pre!=0&&a[i].next!=0)
				{
					ans--;
					int p=a[i].pre;
					int j=a[i].next;
					a[p].sum+=a[j].sum;
					a[j].sum=0;
					while(!a[j].number.empty())
					{
						a[p].number.push(a[j].number.front());
						a[j].number.pop();
					}
					get(j);
					i=a[i].next;
				}
				
			}
			i=a[i].next;
		}
		printf("\n"); 
	}
	return 0;
}
	

2024/8/19 14:02
加载中...