rt,本地样例能过,洛谷全RE。
思路是list+queue的模拟
#include <iostream>
#include <queue>
#include <list>
using namespace std;
struct block{
bool t;
queue<int> q;
};
int n;
list<block> a;
void init()
{
bool type;
block b;
for(int i=1,x;i<=n;i++)
{
scanf("%d",&x);
if(i==1){
type=x;
b.t=x;b.q.push(i);
}
else{
if(x==type)b.q.push(i);
else{
a.push_back(b);
b.t=x;type=x;
while(!b.q.empty())b.q.pop();
b.q.push(i);
}
}
}
a.push_back(b);
return ;
}
int main()
{
cin>>n;
init();
while(n>0){
list<block>::iterator i=a.begin();
bool type=0;
for(;i!=a.end();i++)
{
if(i==a.begin()||i->t!=type){
cout<<i->q.front()<<" ";
i->q.pop();n--;
type=i->t;
}
if(i->q.empty())a.erase(i);
}
cout<<endl;
}
return 0;
}