noip2016 蚯蚓 智商题

来源:互联网 发布:淘宝抓猫猫有什么用 编辑:程序博客网 时间:2024/04/29 02:56

由于D1爆炸,所以D2就没去想正解,只想着打暴力,于是又GG。

首先可以想到优先队列,在外面记录delta。可以做到mlogm,但是m太大。
然后我又去想,q=0既蚯蚓不会变长的时候,切出来的两段蚯蚓分别是单调递减的。这样用三个队列存一下,最大值一定是三个队首中的一个。
一个不那么显然的事情,q!=0的时候这也是成立的(想一想就明白了,难受)。

#include<iostream>#include<cstdio>#include<algorithm>#define LL long longusing namespace std;int a[100005];int b[7000005];int c[7000005];int H[5];int T[5];bool cmp(int a,int b){return a>b;}int main(){    int n,m,q,u,v,t;    scanf("%d%d%d",&n,&m,&q);    scanf("%d%d%d",&u,&v,&t);    for(int i=1;i<=n;i++)        scanf("%d",&a[i]);    sort(a+1,a+n+1,cmp);    int del=0;    H[1]=1;H[2]=1;H[3]=1;T[1]=n;    int cnt=0;    bool fst=0;    for(int k=1;k<=m;k++)    {        int ans=-2e9,p=0;        if(H[1]<=T[1]&&ans<a[H[1]])            ans=a[H[1]],p=1;        if(H[2]<=T[2]&&ans<b[H[2]])            ans=b[H[2]],p=2;        if(H[3]<=T[3]&&ans<c[H[3]])            ans=c[H[3]],p=3;        cnt++;        ans+=del;        if(cnt==t)        {            if(!fst) fst=1;            else printf(" ");            printf("%d",ans);            cnt=0;        }        LL now=(LL)ans*(LL)u;        now/=(LL)v;        del+=q;        b[++T[2]]=(int)now-del;        c[++T[3]]=ans-(int)now-del;        H[p]++;    }    puts("");    int k=n+m;    cnt=0;fst=0;    while(k--)    {        int ans=-2e9,p=0;        if(H[1]<=T[1]&&ans<a[H[1]])            ans=a[H[1]],p=1;        if(H[2]<=T[2]&&ans<b[H[2]])            ans=b[H[2]],p=2;        if(H[3]<=T[3]&&ans<c[H[3]])            ans=c[H[3]],p=3;        ans+=del;cnt++;        if(cnt==t)        {            if(!fst) fst=1;            else printf(" ");            printf("%d",ans);            cnt=0;        }        H[p]++;    }    return 0;}
1 0
原创粉丝点击