#P10323. Expected RSS Minimization
Expected RSS Minimization
Expected RSS Minimization
During a fierce battle remembered from a thousand years ago, Io faced n enemies. The i-th enemy is located at a distinct distance di from her and carries a positive‐integer label vi. Io can launch an attack with power determined by a linear function f(x) = ax+b at any distance. An enemy is eliminated if it is hit with an attack whose power is exactly equal to its label. In practice, Io’s teammates will help her attack, so she only needs to choose the parameters a and b so that the effect is "optimal" in the sense of minimizing the residual sum of squares (RSS)
However, Io does not remember the exact values of the labels. Instead, for the i-th enemy, it is only known that
\(l_i \le v_i \le r_i\), and furthermore, the value of vi is chosen uniformly at random from the interval \([l_i, r_i]\) (all choices being independent).
For any fixed choice of \(v_1,\cdots,v_n\) the linear function that minimizes the RSS is given by classical linear regression. Denote by \(X\) the minimum attainable RSS (which is a random variable because the \(v_i\)'s are random). Io wonders what the expected value \(\mathbb E[X]\) is, and you are to compute it modulo \(998244353\). It can be shown that the answer is always a rational number; output the value \(\mathbb E[X]\) modulo \(998244353\) (using modular inverse if necessary).
Note: The abbreviation RSS stands for "Residual Sum of Squares".
Formulation hint: If the chosen labels are \(v_1,\cdots,v_n\) and the enemy distances are \(d_1,\cdots,d_n\), then the optimal regression line is given by
( a^* = \frac{\sum_{i=1}^{n}(d_i-\bar{d})(v_i-\bar{v})}{\sum_{i=1}^{n}(d_i-\bar{d})^2},\quad b^=\bar{v}-a^\bar{d}, )
where (\bar{d}=\frac{1}{n}\sum_{i=1}^{n}d_i) and (\bar{v}=\frac{1}{n}\sum_{i=1}^{n}v_i). The minimum RSS is then
[ \mathrm{RSS}=\sum_{i=1}^{n}(v_i-\bar{v})^2-\frac{\Bigl(\sum_{i=1}^{n}(d_i-\bar{d})(v_i-\bar{v})\Bigr)^2}{\sum_{i=1}^{n}(d_i-\bar{d})^2}. ]
Your task is to compute the expectation of this quantity over the randomness in the (v_i)'s, modulo (998244353).
inputFormat
The first line contains an integer (n) ((1\le n\le \text{some limit})).
Then (n) lines follow. The (i)-th line contains three integers (d_i, l_i, r_i) separated by spaces, where (d_i) is the distance (all (d_i)'s are distinct) and (l_i, r_i) specify the range from which (v_i) is uniformly drawn (with (1\le l_i\le r_i)).
outputFormat
Output one integer, the expected minimum RSS modulo (998244353).
sample
1
10 5 5
0