蚯蚓-单调队列-迟到的AC代码
早先AC的记录
#include<cstdio>
#include<algorithm>
int CH;
inline void rl(int &x){//read long
/*x=0;*/while((CH=getchar())>57||CH<48);
while(CH>=48&&CH<=57)x=(x<<3)+(x<<1)+CH-48,CH=getchar();
}
inline void rll(long long &x){//read long
/*x=0;*/while((CH=getchar())>57||CH<48);
while(CH>=48&&CH<=57)x=(x<<3)+(x<<1)+CH-48,CH=getchar();
}
bool cmp(const int& a,const int& b){return a>b;}
int n,m,q,v,t;long long u;
int q1[7100006],q2[7100006];//一大一小
int st[100005],top,h1,t1,h2,t2;//两个单调递减队列
//head指向真正的队首, tail指向队尾+1, 即[head,tail)
int len[7100006];
int main(){
rl(n);rl(m);rl(q);rll(u);rl(v);rl(t);top=n;
for(int i=1;i<=n;++i)rl(st[i]);
std::sort(st+1,st+n+1);//是[__first,__last)
if(!m){
printf("\n");for(int i=n,time=1;i;--i,++time)
if(!(time%t))printf("%d ",st[i]);return 0;}
int longest=st[top--],a,b;
//printf("long%d\n"longest);/*两队为空,特判*/
if(t==1)printf("%d ",longest);
a=longest*u/v;b=longest-a-q;a-=q;
q1[t1++]=b,q2[t2++]=a;//printf("xxx:%d %d\n",b,a);
for(int time=2;time<=m;++time)
{
if(!top){
if(q1[h1]>q2[h2])
longest=q1[h1++]+(time-1)*q;//本轮他并没有变长
else//q2队首大
longest=q2[h2++]+(time-1)*q;//本轮他并没有变长
}
else {//栈非空
if(q1[h1]>=q2[h2]&&q1[h1]>=st[top])
longest=q1[h1++]+(time-1)*q;
else if(q2[h2]>=q1[h1]&&q2[h2]>=st[top])
longest=q2[h2++]+(time-1)*q;
else if(st[top]>=q1[h1]&&st[top]>=q2[h2])
longest=st[top--]+(time-1)*q;
}
if(time%t==0)printf("%d ",longest);
a=longest*u/v;b=longest-a-time*q;a-=time*q;
q1[t1++]=b,q2[t2++]=a;
}
putchar('\n');
int ii=1,addlen=m*q;//<2^31
for(;ii<=n+m&&h1<t1&&h2<t2;++ii){
if(q1[h1]>q2[h2])len[ii]=q1[h1++];
else len[ii]=q2[h2++];
}
while(h1<t1)len[ii++]=q1[h1++];
while(h2<t2)len[ii++]=q2[h2++];//q1[h2++];眼睛???
while(top)len[ii++]=st[top--];
std::sort(len+1,len+n+m+1,cmp);
for(int i=1;i<ii;++i)
{
if(i%t)continue;
printf("%d ",len[i]+addlen);
}
return 0;
}