Expected Beauty
Time limit1sMemory limit2048 MB
Each A_i is uniform in [L_i, R_i]. Find the expected maximum score squared when deleting one of two adjacent equal elements adds its value to the score, mod 998244353.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
Morgan the robot has an array of size , indexed from to . The value of each element is random: can be any integer from to (inclusive), each with equal probability.
Morgan defines the beauty of as follows. Morgan has a variable score that starts at . An operation on an array is:
- Choose an index with and . If no such exists, the operation cannot be performed.
- Add the value of to
scoreand remove from the array. - The remaining elements are joined together, keeping their order.
The beauty of is the maximum value of score that Morgan can get after performing zero or more operations on .
Because the array is random, Morgan wants the expected beauty of . Morgan's algorithm is too slow, so Morgan asks for help computing the expected value.
Input
The first line contains an integer (). Each of the next lines contains two integers and ().
Output
Let . The expected value can be written as an irreducible fraction , where . Print one integer on a single line such that and .