NOIP2015PJ T3,T4

Source: Internet
Author: User
NOIP2015 PJ T3,T4 Solution

By-jim H

Sum ... ... ... ... ... ... ... ... ... ... ... ... .... ... .... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 2

Salesman ... ..... .... ... ..... ..... .... ..... ..... ........, ... and .... .....-........... 3

Sum

40%

And the color[z]=color[x],x is the same as the parity of Z

Complexity O (N2)

70%

It means I don't know what this part is for.

100%

Consider optimization

For each x,z we can disassemble the formula

X*NUM[X]+Z*NUM[Z]+X*NUM[Z]+Z*NUM[X]

For each z, we can add a valid prefix with him while doing the edge, plus just fine.

Complexity O (N)

Salesman

We can consider greed.

Because we need to walk the fatigue value, is to go to the far right of the person's fatigue value, the left all have no effect on him.

We set the right side for last.

Obviously this last one divides the whole street into the left and right parts, part of the walking fatigue value has no effect, part of the impact.

It can be seen that, with the increase of X, the best last must be monotonous and non-decreasing.

Because he this last is our combined on both sides of the best value selected, choose the other must not his excellent.

If there are multiple identical values, we can completely greedy to choose the leftmost one. Because he has the least effect on the answer (in fact all the same), but also to maintain the last monotonous non-reduction of

We can maintain the maximum value with two heaps, each x, to see if the new one is on the left or the right, and if you add ans to the left, then delete the total left heap. If you are on the right, add the answer and change last to this number. At this point, we make it from the old last+1 to the new last-1 this part becomes the walking fatigue value has no effect, so we can put each of them from the right side of the heap to delete, add to the left heap is good.

The complexity of the heap is log n, and then the enumeration x is N, and then all the changes in the last operation all add up to N, the complexity is O (2N log N)

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.