#P5654. 基础函数练习题
基础函数练习题
Description
YSGH has a permutation of and an integer sequence of length .
Define:
$$F(l, r) = \begin{cases} \max(F(l, m - 1), F(m + 1, r)) + w_m & , l \le r \\ 0 & , l > r \end{cases}$$where is the index of the maximum value of in the interval .
There are queries asking for the value of .
Input Format
The first line contains two positive integers , with the same meaning as in the statement.
The second line contains positive integers. The -th integer is , with the same meaning as in the statement.
The third line contains integers. The -th integer is , with the same meaning as in the statement.
The next lines each contain two positive integers (), representing a query for .
Output Format
Output lines. Each line contains one integer, which is the answer.
5 2
2 1 5 3 4
2 5 1 2 4
3 5
1 1
7
2
Hint
This problem uses bundled testdata.
- Subtask 1 (10 points): .
- Subtask 2 (10 points): It is guaranteed that is random.
- Subtask 3 (20 points): .
- Subtask 4 (20 points): .
- Subtask 5 (20 points): .
- Subtask 6 (20 points): No special constraints.
For of the data, , , . It is guaranteed that is a permutation of .
Translated by ChatGPT 5
京公网安备 11011102002149号