Describe
- Each query outputs a score of a A/b in a row indicating the probability of randomly extracting two socks of the same color from the range [l,r] of the query.
Analysis
- Interval without modification of the topic, just require a variety of colors, so you can use Mo team.
- If the number of colors I in the interval [L, R] is c[i], then the probability of randomly extracting two socks with the same color is equal to Σc (C[i], 2)/C (r-l+1, 2).
- The M-position of the combined number is found to be 2, so the direct expansion is calculated by σc[i]* (c[i]-1)/[(r-l+1) * (R-L)].
- So the denominator we know that the molecules can be transferred through the state, each time if a new node, the color of a, then the original contribution of a to the molecule is c[i]* (c[i]-1), and then ++c[i], and then let the molecule add now a color to the contribution of the molecule, namely c[i]* (C[I]-1). Delete a node like this. So the time of O (1) is transferred from [L, R] to [L-1, R] or [L+1, r] or [L, R-1] or [L, r+1].
- Then calculate the gcd of the numerator denominator.
- Don't forget to open long long.
bzoj-2038-Little Z's socks hose-team