QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#7482. D2T2

Statistics

Given a sequence of length $n$ and $m$ query operations.

Each query is given as $l\;r\;L\;R$, which means that when we keep the elements of the sequence whose values are within $[L, R]$ unchanged and set all other elements to $0$, we need to find the maximum subarray sum within the range $[l, r]$. The subarray can be empty.

Input

The first line contains two integers $n$ and $m$.

The second line contains $n$ integers representing the sequence.

The following $m$ lines each contain four integers $l\;r\;L\;R$ representing a query operation.

Output

Output $m$ lines, each containing an integer representing the answer.

Examples

Input 1

6 5
-1 1 -4 5 -1 4
1 1 4 5
1 1 4 514
2 3 3 3
1 6 -1 5
2 5 2 5

Output 1

0
0
0
9
5

Note

Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: nzhtl1477

For $100\%$ of the data, $1\leq n,m \le 10^5$, and the absolute value of all numbers in the sequence is $\le 10^9$.

In the fourth query, the value range constraint is $[-1, 5]$, the sequence becomes -1 1 0 5 -1 4, the maximum subarray in the range $[1, 6]$ is $[2, 6]$, and the sum is $9$.

In the fifth query, the value range constraint is $[2, 5]$, the sequence becomes 0 0 0 5 0 4, the maximum subarray in the range $[2, 5]$ is $[4, 4]$ (tied), and the sum is $5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.