Sequence and Queries 10
Time limit2sMemory limit512 MB
For each query with ranges [x1,y1] and [x2,y2], find the maximum subarray sum A_i+...+A_j where i is in the first range and j is in the second.
- Level
Hard8 of 10
- Topics
- Segment tree, Prefix sum, Divide and conquer
- Solved
- No attempts yet
Problem
You are given a sequence of length . Write a program that answers the following query.
x1 y1 x2 y2: print the maximum value of over all pairs with , , and .
Every query in the input satisfies , , , and , so at least one pair always exists.
Input
The first line contains the length of the sequence ().
The second line contains separated by spaces. ()
The third line contains the number of queries ().
Each of the next lines contains one query as four integers , , , , in that order.
Output
Print the answer to each query on its own line.