#P11761. [IAMOI R1] 明码标价
[IAMOI R1] 明码标价
Description
There are items in the mall, where the -th item has price . Since Xiao C has decision fatigue, Xiao L wants to select an item through the following method:
Xiao L neither wants the cheapest item (poor quality) nor the most expensive one (low cost-effectiveness). Therefore, he defines the median of item prices as the price of the middle item after sorting prices in ascending order. Specifically, the median is the price of the -th item after sorting.
Xiao L plans to divide these items into continuous segments based on their utility, then take the median-priced item from each segment. Next, he will take the median of these selected items as the final purchase choice.
However, Xiao C disagrees with this plan because her partitioning differs from Xiao L's. They compromise by adopting the fairest approach: considering all possible partitioning schemes, collect all possible median prices (including duplicates from multiple schemes), then take the median of this collection as the final price.
Given the complexity of possible partitions, they need your help to determine the final selected price.
Formal Problem Statement
Define as the median of multiset , which equals the -th element after sorting in ascending order.
Given a sequence of length , define $f(l,r)=\operatorname{mid}(\{a_l,a_{l+1},\cdots,a_r\})$.
A partition is defined as:
- A sequence of length (where ) satisfying when .
- Two partitions are different if their values differ or any position in differs.
The weight of a partition is:
- When : $\operatorname{mid}(\{f(1,l_1), f(l_1+1,l_2), \cdots, f(l_k+1,n)\})$
- When :
Find the median of the multiset containing weights of all distinct partitions.
Input Format
- The first line contains a single integer .
- The second line contains integers .
Output Format
Output a single integer representing the final selected price.
3
1 2 3
1
Hint
Sample Explanation
For , there are 4 partition schemes:
- → weight
- → weight
- → weight
- → weight
The final multiset is with median .
Constraints
Subtask scoring is used.
| Subtask | Special Property | Score | |
|---|---|---|---|
| 1 | 15 | None | 13 |
| 2 | 40 | A | 17 |
| 3 | None | 20 | |
| 4 | 100 | A | 23 |
| 5 | None | 27 |
Special Property A: is a permutation of .
For all data: , .
Note: In C++, you may use __int128 to store integers in .
Translation by DeepSeek R1
京公网安备 11011102002149号