CE求助QAQ
查看原帖
CE求助QAQ
572482
Dream_weavers楼主2021/12/11 19:35

#include<iostream>
#include<cstdio>
#include<deque>
#include<list>
#define int long long 
const int N=2e5+5;
int n,a[N];
list< deque<int> >v;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	deque<int>t;
	t.push_back(1);
	v.push_back(t);
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1]){
			v.back().push_back(i);
		}else{
			deque<int>tt;
			tt.push_back(i);
			v.push_back(tt);
		}
	}
	while(!v.empty()){
		auto it=v.begin();
		while(it!=v.end()){
			printf("%lld",it->front());
			it->pop_front();
			if(it->empty())it=v.erase(it);
			else it++; 
		}auto last=v.begin();
		if(last==v.end()) break;
		auto now=last;
		now++;
		while(now!=v.end()){
			if(a[last->front()]!=a[now->front()]){
				last=now
				now++;
				continue;
			}if(last->size() < now->size()){
				while(!last->empty()){
					now->push_front(last->back());
					last->pop_back();
				}
				v.erase(last);
				last=now;
				now++
			}else{
				while(!now->empty()){
					last->push_back(now->front());
					now->pop_front();
			    }
			    now=v.erase(now);
			}
		}cout<<endl;
	}
    return 0;
}

QAQ

2021/12/11 19:35
加载中...