Sequence Rotation and Queries
InterviewTime limit1sMemory limit1024 MB
Given an array with right and left rotation queries, answer range sum queries over positions a to b after each rotation.
- Level
Medium4 of 10
- Topics
- Array, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
An integer sequence of length is given. Write a program that handles the following queries.
- : Rotate the sequence to the right by . The value of becomes , becomes , , becomes , becomes , becomes , , and becomes . All values change at the same time.
- : Rotate the sequence to the left by . The value of becomes , becomes , , becomes , becomes , becomes , , and becomes . All values change at the same time.
- : Print the sum of the -th through -th numbers, that is, .
Input
The first line contains and , separated by a space. The second line contains integers , separated by spaces. The next lines each contain one query.
Output
For each type 3 query, print the result on its own line, in the order the queries are given.
Constraints
- Every number in the input is an integer.
- At least one type 3 query is given.