No.1021 Children in Classrooms
Problem Statement
At Yuki Elementary School, $N$ classrooms numbered $1, 2, \ldots , N$ are lined up in a horizontal row in this order from left to right. Initially, classroom $i$ ($1\leq i \leq N$) has $a_i$ children. Teacher Yuki gives $M$ commands. There are $2$ kinds of commands, type L and type R, as follows.
- When a type L command is given, all children in classrooms other than classroom $1$ simultaneously move to the classroom immediately to the left.
- When a type R command is given, all children in classrooms other than classroom $N$ simultaneously move to the classroom immediately to the right.
L, the $i$-th command is of type L, and if $S_i$ is R, the $i$-th command is of type R. Find the number of children in each classroom after the $M$ commands.
Input
$N\ M$ $a_1\ a_2\ \ldots\ a_N$ $S$
- $2\leq N\leq 2\times 10^5$
- $1\leq M\leq 2\times 10^5$
- $0\leq a_i\leq 10^4$
- $N$, $M$, $a_i$ are integers.
- $S$ is a string of length $M$.
- Each character of $S$ is
LorR.
Output
Print $N$ integers separated by spaces. The $i$-th integer from the left ($1\leq i\leq N$) should be the number of children in classroom $i$ after the $M$ commands.
Sample
Sample 1
Input
4 3 3 1 4 1 LRR
Output
0 0 4 5
- After the $1$st command, the numbers of children in classrooms $1, 2, 3, 4$ are $4, 4, 1, 0$, respectively.
- After the $2$nd command, the numbers of children in classrooms $1, 2, 3, 4$ are $0, 4, 4, 1$, respectively.
- After the $3$rd command, the numbers of children in classrooms $1, 2, 3, 4$ are $0, 0, 4, 5$, respectively.
Sample 2
Input
2 7 1 8 LLLLLLL
Output
9 0
From the $2$nd command onward, no one moves.
Sample 3
Input
5 6 314 0 1 5 9 RLRLLR
Output
0 314 1 14 0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
chocorusk