易知可利用优先队列选取最大值;
但是通过分析可知,先取出的蚯蚓分开后仍然要比后分的长,所以可直接利用单调队列找队头即可,分三个单调队列,分别找未切割,切割,切割2三种情况
#include<bits/stdc++.h> #define rep(i,x,y) for(register int i=x;i<=y;i++) #define ll long long using namespace std; const int inf=2147483647; const int N=1e5+5; const int M=7e6+5; int n,m,q,u,v,t,add; int Q[3][M],head[3],tail[3]; inline int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch==‘-‘)f=-1;ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*f;} inline bool cmp(const int &x,const int &y){return x>y;} inline int getmax(){ int res=-inf,k; for(int i=0;i<=2;i++) if(head[i]<tail[i]&&res<Q[i][head[i]+1]) res=Q[i][head[i]+1],k=i; head[k]++;return res;} int main(){ n=read(),m=read(),q=read(); u=read(),v=read(),t=read(); rep(i,1,n) Q[0][++tail[0]]=read(); sort(Q[0]+1,Q[0]+1+tail[0],cmp); rep(i,1,m){ int x=getmax()+add; if(i%t==0) printf("%d",x),putchar(i+t>m?‘\n‘:‘ ‘); int l=(ll)x*u/v,r=x-l; Q[1][++tail[1]]=l-add-q; Q[2][++tail[2]]=r-add-q;add+=q; } if(t>m) putchar(‘\n‘); int tmp=n+m; rep(i,1,tmp){ int x=getmax()+add; if(i%t==0) {printf("%d",x);if(i+t<=tmp) putchar(‘ ‘);} }return 0; }
原文地址:https://www.cnblogs.com/asdic/p/9738129.html
时间: 2024-10-07 00:21:40