链表 TLE#8#9 求调
查看原帖
链表 TLE#8#9 求调
1121087
czy032321054楼主2024/7/14 14:57
#include<bits/stdc++.h>
using namespace std;
int n,a[200005];
struct fruit{
	int l,r,z,last,next;
}f[200005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int l=1,r=1,z=1;
	while(true){
		if(r==n){
			f[z]={l,r,a[l],z-1,0};
			break;
		}
		if(a[r]!=a[r+1]){
			f[z]={l,r,a[l],z-1,z+1};
			z++;
			l=r+1;
		}
		r++;
	}
	f[0].z=9;
	int head=1;
	while(true){
		/*for(int i=1;i<=z;i++)cout<<f[i].l<<"|";
		cout<<endl;
		for(int i=1;i<=z;i++)cout<<f[i].r<<"|";
		cout<<endl;
		for(int i=1;i<=z;i++)cout<<f[i].z<<"|";
		cout<<endl;*/
		for(int i=head;i!=0;i=f[i].next){
			//cout<<f[i].last<<"----"<<f[i].next<<" ";
			if(f[i].l<=f[i].r&&f[i].z!=f[f[i].last].z){
				printf("%d ",f[i].l);
				f[i].l++;
			}
		}
		for(int i=head;i!=0;i=f[i].next){
			if(f[i].r<f[i].l){
				f[f[i].last].next=f[i].next;
				f[f[i].next].last=f[i].last;
				if(i==head)head=f[i].next;
			}
		}
		//cout<<"<"<<head<<">";
		if(head==0)break;
		cout<<endl;
	}
}
2024/7/14 14:57
加载中...