样例三没过,却AC了
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
const ll MAXN=2e5+5;
ll n,a[MAXN];
list<deque<ll>>v;
int main() {
// freopen("fruit3.in","r",stdin);
// freopen("fruit3.out","w",stdout);
scanf("%lld",&n);
for(ll i=1;i<=n;++i){
scanf("%lld",a+i);
}
deque<ll>t;
t.push_back(1);
v.push_back(t);
for(ll i=2;i<=n;++i){
if(a[i]==a[i-1]){
v.back().push_back(i);
}else{
deque<ll>t;
t.push_back(i);
v.push_back(t);
}
}
while(!v.empty()){
for(auto it=v.begin();it!=v.end();++it){
printf("%lld ",it->front());
it->pop_front();
if(it->empty()){
it=v.erase(it);
--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);
}
}
printf("\n");
}
return 0;
}