#P14479. 生成序列
生成序列
Description
Hint: Please note the constraints on and in this problem.
Let denote the length of sequence , and denote the subsequence of from index to inclusive.
Initially, Little L has an empty sequence . Little L can perform the following operations in order several times to eventually transform into the target sequence :
- Generate a sequence such that .
- If there exists such that , then gain point; otherwise, gain points.
- Append sequence to the end of sequence .
Little L wants to know, under the goal of achieving the target sequence, what is the maximum number of points that can be obtained. Let be the answer to this problem when is the target sequence.
To prevent you from cheating Little L, Little L will first give you an array and then perform queries. Each query gives two integers , and you need to answer the value of .
Input Format
The first line contains two integers , representing the length of sequence and the number of queries, respectively.
The second line contains non-negative integers .
Then, lines follow, each with two integers , representing the query interval.
Output Format
Output lines, each containing an integer, representing the value of for each query.
9 2
3 3 3 1 0 2 0 1 0
1 9
2 8
3
1
Hint
【Sample Explanation】
For the first query, the sequence is . One possible way to achieve the maximum points is as follows:
- First operation: let , gain points, now .
- Second operation: let , gain point, now .
- Third operation: let , gain point, now .
- Fourth operation: let , gain point, now .
The total points gained is . It can be proven that no scheme can gain more than points.
【Data Range】
This problem uses bundled tests.
| Subtask | Special Constraints | Score | ||
|---|---|---|---|---|
| None | ||||
| A | ||||
| B | ||||
| None | ||||
- Special Constraint A: .
- Special Constraint B: Each number in sequence appears at most times.
For all data, , , , .
京公网安备 11011102002149号