#P11162. [OOI 2025] Order Statistics
[OOI 2025] Order Statistics
题目描述
You are given an array , , , , consisting of integers, as well as integers and . The following operation is performed times on the array:
- Select , , , --- the positions of the largest elements in the array . If two elements are equal, the element that appears earlier in the array is considered larger.
- Decrease , , , by .
For from to , let denote the value of the -th order statistic in the array obtained from after applying the operation times with the given parameter . For from to , the -th order statistic of the array is the element that would be in position if the array were sorted in non-decreasing order.
For all such that , let denote the sum of for all integers from to . More formally:
You are given integers and . You must compute the values of for all from to .
After that, you must process queries. The -th query () can be one of three types:
- Compute the value of .
- Change the value of to .
- Compute the value of .
All calculations of the functions and are performed independently each time and do not change the array. All changes to the array in queries of the second type are preserved for subsequent queries.
输入格式
The first line contains four integers , , , and (, , , ) --- the length of the array ; the number of operations; the number of largest elements decreased in each operation, and the number of queries.
The second line contains integers (, ) --- the elements of the array .
The next lines contain the queries. In the -th query, the first number is () --- the type of the -th query.
- If , then the next line contains three integers , , and (, )--- the parameters of the first type query.
- If , then the next line contains two integers and (, )--- the parameters of the second type query.
- If , then the next line contains four integers , , , and (, , )--- the parameters of the third type query.
输出格式
In the first line, output integers $F_{m_0,k_0}(1),F_{m_0,k_0}(2),\ldots,F_{m_0,k_0}(n)$.
Then, for each first type query, output the value on a separate line, and for each third type query, output the value ~--- the answer to the -th query.
输入输出样例 #1
输入 #1
8 3 2 16
3 1 2 -1 0 2 -1 4
3 3 2 2 6
1 3 2 4
3 4 5 3 5
1 4 5 6
2 5 -1
2 6 3
1 3 2 1
1 3 2 3
1 3 2 4
1 3 2 8
1 0 5 6
2 1 5
3 1 3 7 8
3 2 3 5 8
3 3 3 4 7
3 4 3 4 7
输出 #1
-1 -1 0 1 1 1 1 2
2
1
-4
-1
-1
-1
1
2
3
7
8
4
2
说明/提示
In the example, , , , . Initially, the array is . Let's see how the array will change if we apply the operation times with parameter :
- The array is . The two largest elements are in positions and . They are decreased by , after which the array becomes .
- The array is . The two largest elements are in positions and . They are decreased by , after which the array becomes .
- The array is . The two largest elements are in positions and . They are decreased by , after which the array becomes .
We find that after applying the operation times with parameter to the array , it becomes . If this array is sorted, it results in the array . Thus, the order statistics are , , , , , , , .
In the example, we need to process queries; let's analyze the first of them in detail:
- The first query is of type , with parameters , , , and requires computing the value of . We have already computed the values of for from to , from which we find the answer to the query:
- The second query is of type , with parameters , , and requires computing the value of . We have already computed it, and it equals .
- The third query is of type , with parameters , , , and requires computing the value of , that is, to calculate the sum of the order statistics from the third to the fifth in the array obtained from after applying the operation times with parameter . At the time of the third query, the array is . The five largest elements are in positions . Decreasing them by , we get the array . Applying the operation three more times, we get the array . After sorting, it becomes . Thus, the answer to the query is
- The fourth query is of type , with parameters , , . After applying four operations with parameter and sorting the array , it will be , so the sixth order statistic is .
- The fifth query is of type , with parameters and . It changes the value of to , after which the array becomes .
- The sixth query is of type , with parameters and . It changes the value of to , after which the array becomes .
- The seventh query requires finding the value of . At the time of the seventh query, the array is . After applying times the operation with parameter , it will be . The first order statistic of this array is .
- The eighth, ninth, and tenth queries require finding the values of , and , that is, the third, fourth, and eighth order statistics in the array . They are equal to , , and , respectively.
Scoring
The tests for this problem consist of eleven groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. means that the results of testing your solution on this group will only be available after the end of the competition.
If there are constraints on or in a subtask, they apply to both and , as well as to the parameters of all first and third type queries.
Group | Points | Additional constraints: | Required Groups | Comment | |||
---|---|---|---|---|---|---|---|
0 | -- | -- | -- | -- | Examples. | ||
1 | 4 | -- | |||||
2 | 5 | -- | -- | ||||
3 | 6 | 2 | for all queries | ||||
4 | 7 | 2, 3 | for all queries | ||||
5 | 11 | -- | -- | ||||
6 | 9 | -- | 1 | ||||
7 | 10 | -- | |||||
8 | 7 | -- | 1, 2, 5 -- 7 | ||||
9 | 11 | 1 -- 3, 5 -- 8 | for all queries | ||||
10 | 13 | 1 -- 3, 5 -- 9 | for all queries | ||||
11 | 9 | 0 -- 10 | -- | ||||
12 | 8 | -- | 0 -- 11 | Offline-evaluation. |