Sushi Belt Lab
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
5.0s
Python 3
5.0s
Memory limit:
977M
Problem type
At the Sushi Belt Lab, plates move on a circular belt. Each plate has an integer flavor value.
You need to process events on the current belt order.
SHIFT k: rotate the belt bykpositions to the right (ifkis negative, rotate left).REVERSE: reverse the order of all sushi on the belt. After this operation, what was previously the right endpoint becomes the left endpoint, and what was previously the left endpoint becomes the right endpoint.SEASON d: adddto every plate's flavor value.TAKE c: remove one plate from an endpoint and print its current value.c = Lmeans the left endpoint.c = Rmeans the right endpoint.
It is guaranteed that every TAKE operation is valid.
Input
The first line contains two integers and
, the initial number of plates and the number of
operations.
The second line contains integers
, the initial flavor values from left to
right.
Each of the next lines is one operation in one of the following formats:
SHIFT kREVERSESEASON dTAKE c
Output
For each TAKE operation, print one line with the removed plate's current flavor value.
Constraints
- Throughout all operations, every plate value fits in signed 64-bit integer range.
Example 1
Input
5 8
3 1 4 1 5
TAKE L
SEASON 2
SHIFT 1
TAKE R
REVERSE
TAKE L
SHIFT -2
TAKE R
Output
3
3
6
7
Explanation
The belt evolves as:
- Start:
[3, 1, 4, 1, 5] TAKE L: print3, belt[1, 4, 1, 5]SEASON 2:[3, 6, 3, 7]SHIFT 1:[7, 3, 6, 3]TAKE R: print3, belt[7, 3, 6]REVERSE:[6, 3, 7]TAKE L: print6, belt[3, 7]SHIFT -2: unchanged (size 2)TAKE R: print7
Comments