跳到正文

题解

题解:AT_abc465_c [ABC465C] Reverse Permutation

Yore_Snow约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月9日
更新
2026年7月14日
篇幅
约 1 分钟
获赞
2

版本

  1. v1当前

因为 i+1i+1 次操作不会影响 ii 次操作,只需要标记当前的序列的顺序是正的还是反的。如果是正的,就将元素放到队列最后,如果是反的,就将元素放到队列前面。

C++
#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;
}
原文
存档评论1 条抓取于