这道题去年看了一下题解,今年没有看题解做,只记得单调队列,然后十分尴尬。
代码并不长(短)
//说明在程序下面
#define N 100010
#define M 7000010
long long n,m,q,u,v,t,topb,lsta,lstb,lstc,topc;
long long a[N],b[M],c[M];
bool cmp(long long a,long long b)
{
return a>b;
}
int main()
{
n=read();
m=read();
q=read();
u=read();
v=read();
t=read();
fr(i,1,n)
a[i]=read();
sort(a+1,a+n+1,cmp);//让a数组满足单调
lsta=1;
lstb=1;
lstc=1;
a[n+1]=-1ll<<60;
fr(_,1,m)
{
long long th;
if(lstb>topb)
b[lstb]=-1ll<<60;
if(lstc>topc)
c[lstc]=-1ll<<60;//避免出现最大为0(没有遍历到)的情况
if(a[lsta]>b[lstb]&&a[lsta]>c[lstc])
{
th=a[lsta];
lsta++;
}
else
if(b[lstb]>c[lstc])
{
th=b[lstb];
lstb++;
}
else
{
th=c[lstc];
lstc++;
}//取最大
th+=(_-1)*q;
if(!(_%t))
printf("%lld%c",th,(_+t>m)?'\n':' ');
b[++topb]=th*u/v;
c[++topc]=th-b[topb];
b[topb]-=_*q;
c[topc]-=_*q;//update
}
if(m<t)
putchar('\n');
fr(i,1,n+m)
{
if(lstb>topb)
b[lstb]=-1ll<<60;
if(lstc>topc)
c[lstc]=-1ll<<60;
long long th=m*q;
if(a[lsta]>b[lstb]&&a[lsta]>c[lstc])
{
th+=a[lsta];
lsta++;
}
else
if(b[lstb]>c[lstc])
{
th+=b[lstb];
lstb++;
}
else
{
th+=c[lstc];
lstc++;
}
if(!(i%t))
printf("%lld%c",th,(i+t>n+m)?'\n':' ');
}
if(n+m<t)
putchar('\n');
return 0;
}
一开始直接跑单调队列,只有两个数组,也就是程序中的
c
数组变成了
然后一个伪懒标记(虽然最终程序也是的)。
然后发现不对劲,接着模拟了一下样例
3 3 2;
3 2;1 0
2;1 0 1 0
b 数组不满足单调了!
存在一组
那么它们依次加入并不一定单调(样例就是一个例子)
然后我们就搞三个数组,因为每次、都是最大,并且加入的都在缩小,所以满足单调的。