60分TLE6、8、9、10点,求调
查看原帖
60分TLE6、8、9、10点,求调
737028
xiamingxuan_IWoLongI楼主2023/8/12 10:05
#include<bits/stdc++.h>
using namespace std;
int n;
struct node {
	int t,x;
} a[500001],b[500001];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i].t;
		a[i].x=i;
	}
	while(1) {
		a[n+1].t=a[n+1].x=-1;
		int t=n;
		int s=1;
		for(int i=1; i<=t; i++)
			if(a[i].t!=a[i+1].t) {
				cout<<a[s].x<<" ";
				a[s].x=a[s].t=-1;
				n--;
				s=i+1;
			}
		int cnt=0;
		for(int i=1; i<=t; i++)
			if(a[i].t!=-1) {
				cnt++;
				b[cnt].t=a[i].t;
				b[cnt].x=a[i].x;
			}
		if(cnt==0)
			break; 
		memset(a,0,sizeof(a));
		for(int i=1; i<=cnt; i++) {
			a[i].t=b[i].t;
			a[i].x=b[i].x;
		}
		cout<<endl;
	}
	return 0;
}
2023/8/12 10:05
加载中...