#P5501. [LnOI2019] 来者不拒,去者不追
[LnOI2019] 来者不拒,去者不追
Description
Given a sequence of length . There are queries. For each query, you need to find the sum of the “Abbi value” of all numbers in the interval .
The Abbi value is defined as follows: if is the -th smallest in the query interval , then its “Abbi value” equals .
To avoid ambiguity, here is an example:
Given the sequence , then is the -st smallest, is the -nd smallest, and is the -th smallest. The sum of Abbi values of the sequence is:
Input Format
The first line contains two integers, and , representing the length of the sequence and the number of queries.
The second line contains numbers. The -th number is , representing the initial value of the sequence.
The next lines each contain two numbers and , representing a query interval.
Output Format
For each query, output one line with the answer.
4 2
1 2 2 3
1 4
1 2
21
5
10 5
8 6 9 8 1 1 3 10 7 9
5 8
1 3
5 7
9 9
5 6
51
49
11
7
2
Hint
Constraints
For the first 2 test points, , time limit .
For the next 14 test points, , , time limit .
For the last 2 test points, , , , time limit .
It is recommended to use fast input. It is recommended to enable optimization.
The testdata has been strengthened.
Translated by ChatGPT 5
京公网安备 11011102002149号