因为 次操作不会影响 次操作,只需要标记当前的序列的顺序是正的还是反的。如果是正的,就将元素放到队列最后,如果是反的,就将元素放到队列前面。
#include <bits/stdc++.h>
#define umm unordered_map
#define xx first
#define yy second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N = 5e5+10;
int n;
deque<int> d;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;string s;
cin >> n >> s;
s = " " + s;
bool f = 0;
for (int i = 1;i <= n;i++){
if (!f) d.push_back(i);
else d.push_front(i);
if (s[i] == 'o'){
f = !f;
}
}
if (f){
while (!d.empty()){
cout << d.back() <<" ";
d.pop_back();
}
}
for (auto i : d){
cout << i <<" ";
}
return 0;
}