51nod加农炮
这道题维护一下前缀最大值然后二分答案就好了哇 233
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int M=50007,inf=2000007; int read(){ int ans=0,f=1,c=getchar(); while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();} return ans*f; } int n,m,mx,k,l,r; int a[M],sum[M]; int main() { n=read(); m=read(); for(int i=1;i<=n;i++) a[i]=read(),mx=max(mx,a[i]),sum[i]=max(sum[i-1],a[i]); //for(int i=1;i<=n;i++) printf("%d ",sum[i]); for(int i=1;i<=m;i++){ k=read(); if(k>mx||k<=a[1]) continue; l=1,r=m; while(l<=r){ int mid=(l+r)>>1; if(sum[mid]<k) l=mid+1; else r=mid-1; } //printf("[%d]\n",l); a[l-1]++; sum[l-1]=max(a[l-1],sum[l-1]); } for(int i=1;i<=n;i++) printf("%d\n",a[i]); return 0; }