#P5648. Mivik的神力
Mivik的神力
Description
$\textcolor{black}{\text{M}} \textcolor{red}{\text{ivik}}$ wants to write an article. While writing, he has candidate words. The -th word has length . $\textcolor{black}{\text{M}} \textcolor{red}{\text{ivik}}$ can choose to start writing from the -th word and write for a total of seconds. In the -th second, he writes the -th word . While writing, he gains happiness points every second. The happiness points in the -th second are . Now please help him compute, for each writing process, the sum of happiness points he gains.
One-sentence statement: Given a sequence and multiple queries , compute
The testdata requires mandatory online processing.
Input Format
The first line contains two integers and , representing the number of words and the number of queries.
The second line contains integers. The -th integer represents .
In the next lines, each line contains two integers and , where and . This represents a query asking for the sum of happiness points when starting from the -th second and writing for seconds.
denotes the answer to the previous query, with initial value .
Output Format
For each query, output one line containing the answer.
3 2
1 2 3
1 1
1 2
2
3
Hint
Sample Explanation
For the first query , after decoding we get . Then according to the statement, the answer is the maximum value on interval , which is .
For the first query , after decoding we get . Then the answer is the sum of the maximum values on intervals and , which is .
For of the testdata, and .
For of the testdata, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号