luogu#P4756. Added Sequence
Added Sequence
Background
Problem Description
Xiao invented a new data structure and named it the array. An array can add or subtract a number to the entire array in time. Now you are given an array of length . He wants to use the array to challenge your computing ability.
Define , where denotes the absolute value of .
Define the beauty of an array as . Each time he adds to the entire array, you need to answer the beauty at that moment.
Note that your algorithm must be online.
Input Format
The first line contains two integers , representing the array length and the number of queries.
The second line contains integers, representing the initial array .
The next lines each contain one integer . Let the previous answer be . Then for the -th query, it means adding to the entire array based on the initial array. Here denotes the modulo operation. For the first answer, .
Output Format
Output lines. The -th line is the beauty of the array after adding to the entire array based on the initial array.
4 4
4 5 6 7
1
15
0
12
6
6
14
26
Hint
The four added numbers are , , , and .
Constraints:
.
.
.
Translated by ChatGPT 5