Mental Arithmetic Board Sum
InterviewTime limit1sMemory limit512 MB
Given an array, apply point assignments and right cyclic shifts, and print the sum of the board after each command.
- Level
Easy3 of 10
- Topics
- Array, Simulation
- Solved
- No attempts yet
Statement
The jury chair of a mental arithmetic championship came up with a new task. Initially integers are written on the board. After that, the contestant must execute commands of two types:
- Erase the -th number and write in its place. The numbers become .
- Cyclically shift the sequence to the right by . The numbers become .
After each command, the contestant must compute the sum of all numbers on the board and report it to the jury. The jury members must compute the required sums themselves to check the answers.
Input
The first line contains an integer , the number of integers initially on the board ().
The second line contains integers separated by spaces: ().
The third line contains an integer , the number of commands ().
Each of the next lines contains one command in one of the following formats:
1 i x: replace the -th number with (; ).2 k: cyclically shift the sequence to the right by ().
Output
Print lines, each containing one integer. The -th line is the sum of the numbers on the board after the first commands.
The answer can be large, so a 64-bit integer type is needed: int64 in Pascal, long long in C++, long in Java.
Hint
In the example from the statement, the initial sequence is . After the first command, the sequence is shifted right by 3 elements, giving with sum . The second command replaces the third element with , giving with sum . The third command replaces the fourth element with . It is already , so the sequence does not change and the sum stays . The fourth command shifts the sequence right by 1, giving . The sum does not change. The fifth command replaces the first element with , giving with sum .