BZOJ4721(NOIP2016)[蚯蚓]--队列

【链接】
bzoj4721

【解题报告】

初看此题好像是堆但好像要被卡常。

所以经过思考以后可以发现:

(1)、其他蚯蚓加一段长度等价于给被切断的蚯蚓减一段长度。

(2)、此次被切断的两段短肯定分别比上次切断的两段短

所以只需要维护三个单调的队列就好了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int maxn=7000005,INF=((1<<30)-1)*2+1;
int n,m,q,u,v,T,S,now,hed[3],til[3],que[3][maxn];
double p;
inline char nc()
{
    static char buf[100000],*l,*r;
    if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
    if (l==r) return EOF; return *l++;
}
inline int Read()
{
    int res=0; char ch=nc();
    while (ch<'0'||ch>'9') ch=nc();
    while (ch>='0'&&ch<='9') res=res*10+ch-48,ch=nc();
    return res;
}
inline bool Cmp(int a,int b) {return a>b;}
void Write(int x) {if (!x) return; Write(x/10); putchar((x%10)+48);}
int MAX()
{

    int x=0;
    if (que[1][hed[1]]>que[x][hed[x]]) x=1;
    if (que[2][hed[2]]>que[x][hed[x]]) x=2;
    return x;
}
int main()
{
    freopen("4721.in","r",stdin);
    freopen("4721.out","w",stdout);
    n=Read(); m=Read(); q=Read(); u=Read(); v=Read(); T=Read();
    for (int i=1; i<=n; i++) que[0][i]=Read();
    sort(que[0]+1,que[0]+1+n,Cmp);
    S=0; now=0; hed[0]=hed[1]=hed[2]=1; que[0][n+1]=-INF; til[1]=til[2]=0;
    for (int i=1; i<=m; i++)
    {
        int x=MAX(),k=que[x][hed[x]++]+now,p1=(LL)k*u/v,p2=k-p1;
        if (!(i%T)) {if (k==0) putchar(48); else Write(k); if ((i/T+1)*T<=m) putchar(32);}
        que[1][++til[1]]=p1-now-q; que[2][++til[2]]=p2-now-q; now+=q;
    }
    putchar(10); que[1][til[1]+1]=que[2][til[2]+1]=-INF;
    for (int i=1,x; i<=n+m; i++)
    {
        x=MAX(),p=que[x][hed[x]++]+now;
        if (!(i%T)) {if (p==0) putchar(48); else Write(p); if ((i/T+1)*T<=n+m) putchar(32);}
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值