luogu#P4756. Added Sequence

Added Sequence

Background

Problem Description

Xiao LL invented a new data structure and named it the LL array. An LL array can add or subtract a number to the entire array in O(1)O(1) time. Now you are given an array aa of length NN. He wants to use the LL array to challenge your computing ability.

Define f(i,j)=p=ijapf(i,j)=|\sum_{p=i}^{j} a_p|, where x|x| denotes the absolute value of xx.

Define the beauty of an array as max1ijNf(i,j)\max_{1 \le i \le j \le N} f(i,j). Each time he adds xx 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 N,MN,M, representing the array length and the number of queries.

The second line contains NN integers, representing the initial array aa.

The next MM lines each contain one integer xix_i. Let the previous answer be prepre. Then for the ii-th query, it means adding [(xi+pre)%(4n+1)2n][(x_i+pre)\%(4n+1)-2n] to the entire array based on the initial array. Here %\% denotes the modulo operation. For the first answer, pre=0pre=0.

Output Format

Output MM lines. The ii-th line is the beauty of the array after adding xix_i 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 7-7, 4-4, 2-2, and 11.

Constraints:

1N,M2000001 \le N,M \le 200000.

ai200000|a_i| \le 200000.

0xi8000000 \le x_i \le 800000.

Translated by ChatGPT 5