dalao求优化!!!玄关
查看原帖
dalao求优化!!!玄关
1271341
chu_yh楼主2024/10/6 21:56
#include<bits/stdc++.h>
using namespace std;
const int Max=2e5+5;
priority_queue<int,vector<int>,greater<int> > q;
pair<int,bool> f[Max];
bool mark;
int n,t;

int main(){
//	freopen("fruit.in","r",stdin);
//	freopen("fruit.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&f[i].first);
	q.push(1);
	f[1].second=true;
	t=1;
	f[0].first=2;
	int m=n-1;
	while(m>0){
		if(mark) t=0;
		for(int i=2;i<=n;i++){
			if(!f[i].second&&f[t].first!=f[i].first){
				m--;
				q.push(i);
				f[i].second=true;
				t=i;
			}
		}
		while(!q.empty()){
			printf("%d ",q.top());
			q.pop();
		}
		putchar('\n');
		mark=true;
	}
	return 0;
}

TLE后三个点

2024/10/6 21:56
加载中...