UOJ264 "NOIP2016" earthworms

Source: Internet
Author: User

This article is copyright ljh2000 and Blog Park is shared, welcome reprint, but must retain this statement, and give the original link, thank you for your cooperation.

this article ljh2000
Author Blog: http://www.cnblogs.com/ljh2000-jump/
Reprint please specify the source, infringement must investigate, retain the final interpretation right!

Descriptionin this subject, we will use the symbol [C] to represent the downward rounding of C, for example: [3.0"= [3.1"=[3.9"=3. Cricket the worm has been a disaster recently! Next Door JumpFlea Country Flea also take earthworms have no way, cricket King had to ask God knife hand to help them destroy earthworms. There are now n earthworms in the cricket state (n is the positive integernumber). Each earthworm has a length, we set the first earthworm to A_i (i=1,2,..., N) and ensure that all lengths are non-negative integers (i.e.,can exist in the length of 0 earthworms). Every second, the sword hand will find the longest one in all earthworms accurately (if there are more than one)cut it in two halves. The position of the worm is determined by the constant P (which is the rational number satisfying the 0<p<1), and the length of the worm is X, and the sword hand willcut into two earthworms of the length [PX] and x-[px] respectively. Specifically, if one of these two numbers equals 0, the worm of this length of 0 will also bereserved. Furthermore, in addition to the two new earthworms that have just been produced, the length of the remaining earthworms increases Q (which is a nonnegative integer constant). King Cricket knows this is notis a long-term one, because earthworms will not only become more and more, but will grow longer. King Cricket decided to resort to a mysterious figure with a primitive force, butThe reinforcements also need m seconds to come ... (M is a non-negative integer) King Cricket wants to know what's in this M-second. Specifically, he wanted to know:? m in seconds, the length of the worm that was cut off every second (with the number of M) before being cut off? m seconds, the length of all earthworms (with n+m number). King Cricket, of course, knows how.Do it! But he wants to test you ... InputThe first line contains six integer n,m,q,u,v,t, wherein: The meaning of N,m,q is described in the question;u,v,t are all positive integers; you need to calculate your own p=u/v (guaranteed 0<u<v) T is an output parameter, meaning it will be interpreted in the output format. The second line contains n non-negative integers, ai,a2,..., An, which is the length of the initial n earthworms. The adjacent two numbers in the same row are separated by exactly one space. guaranteed 1<=n<=10^5,0<m<7*10^6,0<u<v<10^9,0<=q<=200,1<t<71,0<ai<10^8.  OutputThe first line outputs [m/t] integers, in chronological order, output t seconds, 2t seconds, 3t seconds ... The length of the worm being cut off (before being cut off). The second line outputs [(N+M)/t] integers, outputting the length of the earthworm after m seconds; need to be in order from large to smalloutput rank T, section 2t, 3t ... The length. The adjacent two numbers in the same row are separated by exactly one space. You should output a blank line even if a row does not have any number to output. Please read the sample to better understand this format.  Sample Input3 7 1 1 3 1
3 3 2Sample Output3 4 4 4 5 5 6
6 6 6 5 5 4 4 3 2 2   Positive solution: Monotone queueProblem Solving Report: 60 min

Consider taking a maximum value each time this operation, the heap to maintain the more convenient, but each time adding a Q seems to be difficult to handle. We consider adding a global variable tag, which means that each number needs to be tagged, so you can avoid adding to all the elements in the heap, instead of subtracting Q for each new two element and then putting it into the heap. Specific practices: System heap Maintenance, each time the largest element, and then add tag, get the real value, calculated two new element value, tag plus q, two new element value minus tag, thrown into the heap.

65 min

The system heap constant is too large, plus the speed of the CCF evaluation machine is limited, the point of 30w is just card T. A 18th test point can be passed to the handwritten heap.

90 min

Note that q=0 also has a lot of partial points, if we can solve the situation of q=0, plus the above algorithm, you can get 90 points.

First of all, Q=0 said that each time there is no self-increment operation, it is easy to find that all the elements are in the monotonous decline (or not increase), that is, each time the largest element is not increased, which means that the cut off after the two new elements, must be smaller than any previous cut after the new elements.

It is a revelation to us that it seems to be monotonous at the time of q=0. We maintain three queues of Q1, Q2, Q3. The initial Q1 is the number of n from large to small, and the q2,q3 is empty. Each operation, take out three queue of the first element of the team the largest, set to X, the PX dropped into the Q1, x-px thrown into the Q2. According to what we have said above, we can guarantee that any time it is taken out is not increased, so we can ensure that the three queues at any time are monotonous and non-increasing. This allows you to pass the 90% test point.

100 min

By studying the monotony of q=0, we can find that the q≠0 is also monotonous.

When we are q≠0, we assume that we do not satisfy monotonicity, that is, there is a previous division of a, in the middle of the interval of N-round, the split element in a division when it is B, then this is b+n*q, and B cut out the part than before a cut out to be long. Assuming the above situation exists, the description satisfies:

$${a*p+n*q< (B+N*Q) *p (only consider multiplying the portion of P)}$$

Because of the a>=b, and the right to expand after the $${b*p+n*q*p}$$ because of p<1, and a>=b, obviously the style is not established. This can be explained by contradiction.

The correctness of the algorithm can also be proved from the monotonic point of view: because we take one element x each time, divide it into two parts, then add the whole to Q, then the two new elements-Q. Does that mean that the values of the elements that are saved in the queue are still monotonically decreasing (because there is no addition operation, only because it is divided into two halves and becomes smaller)? That is, regardless of how the change, this global increment tag will not affect the relative size, because tag for the object is the whole element, so if the size of the case of the loss of the tag is satisfied with the tag after the addition of tags is obviously satisfied, because plus a number, the relative size does not change. So we can find that in the q≠0, the elements in the queue also satisfy the monotony, apply the above algorithm can get full marks.

Precautions

Because the topic is not directly given by P, but by giving the numerator denominator requires us to calculate p, to reduce the accuracy error. When you multiply, you need to open a long long temporary variable, but then turn it into Int. The rest can only open int.

 
1 //It's made by ljh20002#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> -#include <string> - using namespacestd; thetypedefLong LongLL; - Const intMAXN =7000011;  - ConstLL inf = (1ll<< -); - intn,m,q,t,tag,q[3][maxn],head[3],tail[3]; + LL u,v; -  +InlineintGetint () { A     intw=0, q=0;CharC=getchar (); while((c<'0'|| C>'9') && c!='-') c=GetChar (); at     if(c=='-') q=1, C=getchar (); while(c>='0'&&c<='9') w=w*Ten+c-'0', C=getchar ();returnq?-w:w; - } -InlineBOOLcmpintQintQQ) {returnQ>QQ;} -InlinevoidWork () { -N=getint (); M=getint (); Q=getint (); U=getint (); V=getint (); T=getint ();intLJH1,LJH2, from; LL now;int  out=0; -      for(intI=1; i<=n;i++) q[0][i]=getint (); Sort (q[0]+1, q[0]+n+1, CMP); tag=0; head[0]=head[1]=head[2]=1; tail[0]=n; tail[1]=tail[2]=0; in      for(intI=1; i<=m;i++) { -Now=-inf; from=-1; for(intj=0;j<3; j + +)if(Head[j]<=tail[j]) {if(Q[j][head[j]]>now) {Now=q[j][head[j]]; from=J;} } toNow+=tag; out++;if( out==t) {printf ("%lld", now); out=0; } +ljh1=now*u/v; LJH2=NOW-LJH1; head[ from]++; tag+=Q; -Ljh1-=tag; ljh2-=tag; theq[1][++tail[1]]=LJH1; q[2][++tail[2]]=Ljh2;  *     } $printf"\ n"); M+=n; out=0;Panax Notoginseng      for(intI=1; i<=m;i++) { -Now=-inf; from=-1; for(intj=0;j<3; j + +)if(Head[j]<=tail[j]) {if(Q[j][head[j]]>now) {Now=q[j][head[j]]; from=J;} } theNow+=tag; out++;if( out==t) {printf ("%lld", now); out=0; } +head[ from]++; A     } the } +  - intMain () $ { $ Work (); -     return 0; -}

UOJ264 "NOIP2016" earthworms

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.