AtCoder Beginner Contest 237 D - LR insertion

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=s1​s2​…sN​, consisting of L and R.

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 or R.

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​ is L, which makes it A=(1,0).
S2​ is R, which makes it A=(1,2,0).
S3​ is R, which makes it A=(1,2,3,0).
S4​ is L, which makes it A=(1,2,4,3,0).
S5​ is R, 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->头部添加

相当于就是说将整个过程“倒叙”过来,便于计算

完结撒花❀

*★,°*:.☆( ̄▽ ̄)/$:*.°★* 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码,好简单。(请点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞点赞)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值