6808.Subarray Sum Queries

Time Limit: 1s Memory Limit: 512MB

There is an array consisting of $n$ integers. Some values of the array will be updated, and after each update, your task is to report the maximum subarray sum in the array.

Input Format(From the terminal/stdin)

The first input line contains integers $n$ and $m$ : the size of the array and the number of updates. The array is indexed $1,2,\ldots,n$ .

The next line has $n$ integers: $x_1,x_2,\ldots,x_n$ : the initial contents of the array.

Then there are $m$ lines describing the changes. Each line has two integers $k$ and $x$ : the value at position $k$ becomes $x$ .

  • $1 \le n, m \le 2 \cdot 10^5$
  • $-10^9 \le x_i \le 10^9$
  • $1 \le k \le n$
  • $-10^9 \le x \le 10^9$

Output Format(To the terminal/stdout)

After each update, print the maximum subarray sum. Empty subarrays (with sum $0$ ) are allowed.

Sample Input

Copy
5 3
1 2 -3 5 -1
2 6
3 1
2 -2
 · \n
 · ·  · ·  \n
 · \n
 · \n
 ·  \n

Sample Output

Copy
9
13
6
 \n
  \n
 \n
Source: CSES, Range Queries, 1190

Submit

请先 登录

© 2025 FAQs