6809.Subarray Sum Queries II

Time Limit: 1s Memory Limit: 512MB

You are given an array of $n$ integers and $q$ queries. In each query, your task is to calculate the maximum subarray sum in the range $[a,b]$ .

Empty subarrays (with sum $0$ ) are allowed.

Input Format(From the terminal/stdin)

The first line contains two integers $n$ and $q$ : the number of elements and the number of queries.

Then there are $n$ integers $x_1,x_2,\ldots,x_n$ : the contents of the array.

Finally there are $q$ lines that describe the queries. Each line has two integers $a$ and $b$ .

  • $1 \le n, q\le 2 \cdot 10^5$
  • $-10^9 \le x_i \le 10^9$
  • $1 \le a \le b \le n$

Output Format(To the terminal/stdout)

Print the answer for each query.

Sample Input

Copy
8 4
2 5 1 -2 3 -1 -7 1
2 4
2 5
6 7
4 8
 · \n
 · · ·  · ·  ·  · \n
 · \n
 · \n
 · \n
 · \n

Sample Output

Copy
6
7
0
3
 \n
 \n
 \n
 \n
Source: CSES, Range Queries, 3226

Submit

请先 登录

© 2025 FAQs