RE all
查看原帖
RE all
809708
whssy楼主2023/8/7 18:00
#include<cstdio>
#include<queue>
#include<list>
//#include<bitset>
#include<vector>
using namespace std;
const int N=2e5+5;
struct node{
	bool flag;
	queue<int>data;
};
list<node>l;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		bool temp;
		scanf("%d",&temp);
		if(l.empty()){
			node t;
			t.flag=temp;
			t.data.push(i);
			l.push_back(t);
		}else if(temp!=l.back().flag){
			node t;
			t.flag=temp;
			t.data.push(i);
			l.push_back(t);
		}else{
			auto x=--l.end();
			x->data.push(i);
		}
	}
	while(!l.empty()){
		vector<int>ans;
		for(auto x=l.begin();x!=l.end();x++){
			ans.push_back(x->data.front());
			x->data.pop();
			if(x->data.empty())
				l.erase(x);
		}
		for(auto x=++l.begin();x!=l.end();x++){
			auto y=x;y--;
			if(x->flag==y->flag){
				while(!y->data.empty()){
					x->data.push(y->data.front());
					y->data.pop();
				}
				l.erase(y);
			}
		}
		for(int e:ans)
			printf("%d ",e);
		putchar('\n');
	}
	return 0;
}
2023/8/7 18:00
加载中...