D - LR insertionhttps://atcoder.jp/contests/abc237/tasks/abc237_dEditorial - AtCoder Beginner Contest 237AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc237/editorial/3319Problem Statement
There is a sequence that contains one 0, A=(0).
Additionally, you are given a string of length N, S=s1s2…sN, consisting ofL
andR
.For each i=1,2,…,N in this order, the following will be done.
- If si is
L
, insert ii to the immediate left of i−1in A.- If si is
R
, insert ii to the immediate right of i−1 in A.Find the final contents of A.
Constraints
- 1≤N≤5×105
- N is an integer.
- |S| = N
- si is
L
orR
.
Input
Input is given from Standard Input in the following format:
N S
Output
Print the final contents of A, separated by spaces.
Sample Input 1
5 LRRLR
Sample Output 1
1 2 4 5 3 0
Initially, A=(0)A=(0).
S1 isL
, which makes it A=(1,0).
S2 isR
, which makes it A=(1,2,0).
S3 isR
, which makes it A=(1,2,3,0).
S4 isL
, which makes it A=(1,2,4,3,0).
S5 isR
, which makes it A=(1,2,4,5,3,0).
Sample Input 2
7 LLLLLLL
Sample Output 2
7 6 5 4 3 2 1 0
简易翻译:
题目描述
这里有一个只包含0的序列 A=(0)
另外,你会用一个长度为N的字符串S (S1S2S3…SN) S串包含L和R
对于每一个ii位置(1≤i≤N1≤i≤N)有如下操作
- 如果 si 是 L 则在A序列的i-1位置的左侧插入数字i
- 如果 si 是 R 则在A序列的i-1位置的右侧插入数字i
请找出最终的字符串A
输入格式
第一行,一个数N 第二行,一个字符串S
输出格式
操作后的A数组
输入数据
5 LRRLR
输出数据
1 2 4 5 3 0
解释
刚开始, A=(0).
L ,A = (1,0) R ,A = (1,2,0). R ,A = (1,2,3,0). L ,A = (1,2,4,3,0). R ,A = (1,2,4,5,3,0).
数据范围
1≤N≤5×105
N是一个整数
|S|=N
si 只会是L或R
分析
用deque(STL)容器,定义一个长度为1,元素为n(输入的N)的(long long)容器
for循环,从n-1到0遍历字符串指令,L->末尾添加 | R->头部添加
相当于就是说将整个过程“倒叙”过来,便于计算
完结撒花❀
*★,°*:.☆( ̄▽ ̄)/$:*.°★*