为什么全是TLE???
查看原帖
为什么全是TLE???
358467
Hz_pro楼主2022/2/1 18:02
#include<bits/stdc++.h>
using namespace std;
struct node{
	int pre,nxt,value;
}t[1000005];
struct list{
	int len,bgn=1,nd;
	node &operator[](int i)
	{
		return t[i];
	}
	void push(int x)
	{
		t[len].nxt=++len;
		t[len].value=x;
		t[len].pre=len-1;
		nd++;
	}
	void erase(int x)
	{
		if(x==bgn)bgn=t[x].nxt;
		if(x==nd)nd=t[x].pre;
		t[t[x].nxt].pre=t[x].pre;
		t[t[x].pre].nxt=t[x].nxt;
		len--;
	}
}a;
int n,x;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>x,a.push(x);
	while(a.len)
	{
		for(int i=a.bgn;i<=a.nd&&i!=0;i=a[i].nxt)
		{
			cout<<i<<' ';
			a.erase(i);
			while(i<=a.nd&&a[i].value==a[a[i].nxt].value&&a[i].nxt!=0)i=a[i].nxt;
		}
		puts("");
	}
	return 0;
}
2022/2/1 18:02
加载中...