Array and Operations
InterviewTime limit2sMemory limit512 MB
Apply a sequence of global 'add index to each position' updates and range reversals to a zero array, then report the values at m queried positions.
- Level
Medium7 of 10
- Topics
- Array, Implementation, Math, Simulation
- Solved
- No attempts yet
Problem
You have an integer array of size , initialized with all zeros. You will apply operations to this array times.
There are two kinds of operations.
- Add: add to every . ()
- Reverse: a reverse operation needs two indices and with . It reverses the order of the elements from through . That is, the order of is reversed.
For example, let and consider applying the following five operations in order.
- Add
- Add
- Reverse with ,
- Add
- Reverse with ,
Initially is . The result after each operation is as follows.
Given the size of the array, the number of operations applied, and the operations themselves, you want to determine the values stored in .
Given an array of size , find the value of after all operations have been applied.
Input
The first line contains three integers , , . (, , )
The next lines contain the operations, one per line. Each line starts with 'a' or 'r'. 'a' denotes an add operation and 'r' denotes a reverse operation. When the line starts with 'r', it is followed by two space-separated integers and . ()
The last line contains integers that describe the array , in order. ()
Output
Print the value of on each of lines, one per line, in order.