bzoj-2038-Little Z's socks hose-team

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.