#P10323. 理性(Rationality)
理性(Rationality)
Background
The goodness of mathematics, the fundamental principle that rules the universe — rationality.
“Light of Rationality” Io is an ancient elf graphic spellcaster. Even at a thousand years old, she can always make the best decisions rationally, without being disturbed by emotions.
Problem Description
Update during the contest: Note that for a fixed set of , the minimum value of can always be computed. **It is a random variable depending on the random variables X\mathbb E[X]$. Typo fix: The English abbreviation for the residual sum of squares is$\text{RSS}$.
Io’s thoughts returned to a great battle a thousand years ago.
She remembers that there were enemies in that battle. The -th enemy was at a distance from her (all are distinct). Each enemy carried a positive integer label . As long as it is hit with exactly attack power , it can be eliminated.
She only needs to set a linear function , and she can release attack power at distance . Fortunately, her teammates will assist with the attacks, so she only needs to choose to make the effect of optimal, i.e., minimize (residual sum of squares):
Of course, this is only her memory. She can clearly remember each distance , but for she only remembers that it satisfies .
She wants to know, assuming each is uniformly random within , the expected value of the “minimum value of ”.
It can be proven that the answer is always a rational number. You only need to output the result modulo .
Input Format
The first line contains a positive integer , denoting the number of enemies.
The next lines each contain three positive integers , denoting the distance from Io to the -th enemy, and the lower and upper bounds of its label .
To make computation easier, Io guarantees that (), and also that:
$$n\sum_{i=1}^nd_i^2 \not \equiv \left(\sum_{i=1}^nd_i \right)^2 \pmod{998244353}$$This ensures that the answer always exists modulo .
Output Format
Output one integer in a single line, denoting the expected value of the minimum over all cases.
3
1 4 4
3 7 7
5 10 10
0
5
1 4 4
2 5 5
3 7 7
4 8 8
9 8 8
488831003
5
1 1 4
2 2 5
3 3 7
4 2 8
9 3 8
884183796
10
123 1 10
234 11 14
345 10 20
456 6 6
567 20 30
678 84 90
789 1 3
8910 8 15
91011 123 129
101112 56 64
483360041
Hint
[Sample Explanation]
In this sample, , so the case is fully determined, and you only need to find the optimal . It is easy to see that the three data points can be perfectly fitted by a linear function, i.e., . The deviation at each point is , so the expected minimum , i.e., the answer, is .
[Sample Explanation]
Here we also have . The data for the enemies are . It can be proven that choosing
gives a solution that minimizes . Substituting and computing,
$$\text{RSS}=\sum_{i=1}^n\left( \frac{87}{194}d_i+\frac{911}{194}-v_i\right)^2=\frac{1047}{194}$$Modulo , the answer is .
[Constraints]
This problem uses bundled testdata.
Subtask 1 (10 pts): .
Subtask 2 (10 pts): .
Subtask 3 (15 pts): , .
Subtask 4 (15 pts): .
Subtask 5 (20 pts): .
Subtask 6 (30 pts): no special constraints.
For all testdata, , , , (), and:
$$n\sum_{i=1}^nd_i^2 \not \equiv \left(\sum_{i=1}^nd_i \right)^2 \pmod{998244353}$$[Hint]
This problem asks for the expected value of the “minimum value of ”. For a discrete random variable , suppose it can take values with probabilities (). Then its expected value is defined as:
For how to compute a rational number modulo a prime, please refer to the template problem.
Translated by ChatGPT 5