Modern Machine
Time limit2.5sMemory limit1024 MB
Given N light tiles and M buttons, answer Q queries that ask how many tiles are red after pressing buttons L to R in order.
- Level
Hard8 of 10
- Topics
- Simulation, Segment tree, Divide and conquer
- Solved
- No attempts yet
Problem
Bitaro was given a JOI machine as a birthday present. The JOI machine consists of one ball, light tiles, and buttons. The light tiles are numbered from to . When Bitaro turns the power on, light tile () emits light of color (blue B or red R). The buttons are numbered from to . When Bitaro pushes button (), the following happens.
- The ball is placed on light tile .
- Light tile becomes red, regardless of its original color.
- The following steps repeat until the ball is removed.
- Let be the index of the light tile where the ball currently is.
- If light tile is blue, light tile becomes red. Then, if , the ball is removed. Otherwise, the ball moves to light tile .
- If light tile is red, light tile becomes blue. Then, if , the ball is removed. Otherwise, the ball moves to light tile .
Bitaro runs experiments. In the -th experiment (), Bitaro turns the power on, then pushes buttons in this order. After he pushes a button, he waits until the ball is removed before pushing the next one. For each experiment, find the number of light tiles that are red when the experiment finishes.
Input
The input is given in the following format.
Output
Print lines. On the -th line, print the number of light tiles that are red when the -th experiment finishes.
Constraints
- .
- .
- () is either
BorR. - ().
- .
- ().
- , , , , , are integers.