O(n)题解
2026-10-03 15:45:02
发布于:浙江
2阅读
0回复
0点赞
set容器模版(模拟)
#include<bits/stdc++.h>
using namespace std;
set<int> s[2];
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int t;
cin>>t;
s[t].insert(i);
}
while(1){
if(s[0].empty()){
for(auto i:s[1]){
cout<<i<<endl;
}
return 0;
}
if(s[1].empty()){
for(auto i:s[0]){
cout<<i<<endl;
}
return 0;
}
int t=*s[1].begin()<*s[0].begin();
int w=0;
while(1){
auto it=s[t].upper_bound(w);
if(it==s[t].end()){
break;
}
cout<<*it<<" ";
w=*it;
s[t].erase(it);
t^=1;
}
cout<<endl;
}
}
这里空空如也







有帮助,赞一个