1. 程式人生 > >【JZOJ4907】蚯蚓

【JZOJ4907】蚯蚓

description


analysis

  • 暴力堆是部分分,但正解是亂搞

  • 可以證明或者腦補出來,先被砍半的蚯蚓的兩部分一定比後砍半的蚯蚓的兩部分要先砍

  • 因為先砍的蚯蚓本來就比後面的蚯蚓長,所以各砍半後也是前面的蚯蚓的兩部分長

  • 所以用三個佇列,第一個佇列存下原來的陣列降序排列

  • 每次取出三個佇列的隊頭的最大值,砍半之後塞到第二、三個佇列裡就可以了


code

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAXN 10000005
#define INF 1000000007
#define ll long long
#define reg register ll
#define fo(i,a,b) for (reg i=a;i<=b;++i)
#define fd(i,a,b) for (reg i=a;i>=b;--i)

using namespace std;

ll a[3][MAXN],top[3],len[3];
ll n,m,q,u,v,t,mx,where;

inline bool cmp(ll x,ll y)
{
	return x>y;
}
inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while (ch<'0' || '9'<ch){if (ch=='-')f=-1;ch=getchar();}
	while ('0'<=ch && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int main()
{
	//freopen("readin.txt","r",stdin);
    freopen("earthworm.in","r",stdin);
   	freopen("earthworm.out","w",stdout);
    n=read(),m=read(),q=read(),u=read(),v=read(),t=read();
    fo(i,1,n+m)a[0][i]=a[1][i]=a[2][i]=-INF;
    fo(i,1,n)a[0][i]=read();
    sort(a[0]+1,a[0]+n+1,cmp);
    top[0]=top[1]=top[2]=1,len[0]=n;
    fo(i,1,m)
    {
        mx=-INF;
        fo(j,0,2)if(a[j][top[j]]>mx)mx=a[j][top[j]],where=j;
        mx+=(i-1)*q,++top[where];
        if (i%t==0)printf("%lld ",mx);
        ll x=mx*u/v,y=mx-x;
        a[1][++len[1]]=x-i*q,a[2][++len[2]]=y-i*q;
    }
    printf("\n");
    fo(i,1,n+m)
    {
        mx=-0x7fffffff;
        fo(j,0,2)if(a[j][top[j]]>mx)mx=a[j][top[j]],where=j;
        mx+=m*q,++top[where];
        if (i%t==0)printf("%lld ",mx);
    }
}