P9681 Humorous World.
Background
@【data deleted】: What do you all think? || @【data deleted】: OI life is always full of humor. But maybe studying school subjects is not much better?
Description
Given a sequence $a_1,a_2,\cdots,a_n$ of length $n$, define a contiguous subsequence $a_l,a_{l+1},\cdots,a_r$ to be humorous if and only if:
- $\sum\limits_{i=l}^r a_i>0$;
- For all $l\le x\le y
Input Format
The first line contains two integers $n,q$.
The next line contains $n$ integers, where the $i$-th integer is $a_i$.
The next $q$ lines each contain two integers $l,r$, representing a query.
Output Format
For each query, output one integer per line, which is the answer.
Explanation/Hint
For all testdata, it is guaranteed that $1\le n,q\le 2\times 10^5$, $1\le l\le r\le n$, and $|a_i|\le 10^9$.
### Subtasks
| # | Special Property | Score |
| :--: | :-----------------------: | :---: |
| 0 | Sample | 0 |
| 1 | $n,q\le 50$ | 15 |
| 2 | $n,q\le 3\times 10^3$ | 20 |
| 3 | For all queries, $r=n$ | 15 |
| 4 | For all queries, $l=1$ | 15 |
| 5 | - | 35 |
Translated by ChatGPT 5