$ Noip2016 / Luogu2827 $ earthworm

$ Luogu $

 

$Sol$

At first glance, is a pair of analog, with priority queues maintenance is not enough. But there is a problem is how to solve the problem of growth has not been cut earthworms can be so treated, each cut an earthworm, to cut finished after subtracted $ q $, plus the final output will answer $ q * m $ to $ OK $ spicy. there is also a place to note is that each earthworms cut out when they are required, rather than its actual length there is a priority queue length.

But this is only $ 80 $ like. Blind wave analysis seems complexity $ O (mlog_ {n + m} ^ 2) $.

Consider optimizing, if we can this $ log ^ 2 $ remove enough acridine.

Note, a longer period before the cut after the cut must be greater than earthworms earthworm longer period, the first short section of the cut must be greater than earthworms cut after a short period. Thus not required priority queue can maintain the monotonicity specifically open three arrays, each memory has not been cut worms (initial array, remember sort), the longer the earthworms after being cut, after being cut short earthworms each time three array select the longest cut, finish cut after the addition of the two arrays are not required behind enough extra maintenance.

 

$Code$

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
int r()
{
    int x=0,y=1;;char ch;
    ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') y=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}  
    return x*y;
}
bool cmp(int x,int y)
{
    return x>y;
}
int q[8000010],q1[8000010],q2[8000010];
int n,m,qq,u,v,t;
double p;
int a[100010];
int rem;
priority_queue<int> ans;
int main()
{
    n=r();m=r();qq=r();u=r();v=r();t=r();
    p=(double)u/(double)v;
    for(register int i=1;i<=n;i++) q[i]=r();
    sort(q+1,q+n+1,cmp);
    int h=1;
    int h1=1,t1=0,h2=1,t2=0;
    int top;
    for(register int i=1;i<=m;i++)
    {
        if(h>n) {if(q1[h1]>q2[h2]) top=q1[h1++];else top=q2[h2++];}
        else if(q[h]>=q1[h1]&&q[h]>=q2[h2]) top=q[h++];
        else if(q1[h1]>=q2[h2]) top=q1[h1++];
        else top=q2[h2++];
        top+=rem;
        int x1=floor((double)top*p),x2=top-x1;
        rem+=qq;
        x1-=rem;x2-=rem;
        q1[++t1]=x1;q2[++t2]=x2;
        if(i%t==0) printf("%d ",top);
    }
    printf("\n");
    for(register int i=h;i<=n;i++) ans.push(q[i]);
    for(register int i=h1;i<=t1;i++) ans.push(q1[i]);
    for(register int i=h2;i<=t2;i++) ans.push(q2[i]);
    for(int i=1;ans.size();i++)
    {
        if(i%t==0) printf("%d ",ans.top()+rem);
        ans.pop();
    }
    return 0;
}
View last year's Code

 

 

 

Guess you like

Origin www.cnblogs.com/forward777/p/11408025.html