题解
2025-08-26 22:22:40
发布于:浙江
3阅读
0回复
0点赞
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
int main(){
cin >> n;
set<ll> a[2];
for(ll i=1;i<=n;i++){
ll x;
cin>>x;
a[x].insert(i);
}
while(!a[0].empty()||!a[1].empty()){
ll c=1;
if (a[0].empty()) c=1;
else if (a[1].empty()) c=0;
else if (*a[0].begin()<*a[1].begin()) c=0;
vector<ll> p;
ll l=0;
while(1){
auto it=a[c].upper_bound(l);
if(it==a[c].end())break;
p.push_back(*it);
l=*it;
a[c].erase(it);
c=!c;
}
for(ll t:p){
cout<<t<<' ';
}
cout << "\n";
}
return 0;
}
这里空空如也
有帮助,赞一个