#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N =200005;
int maxn[N<<2];
int h,w;
void build(int l,int r,int rt){
if(l==r){
maxn[rt]=w;
return;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
maxn[rt]=w;
}
int query(int l,int r,int x,int rt){
if(l==r) {
maxn[rt]-=x;
return l;
}
int mid=(l+r)>>1;
int pos;
if(maxn[rt<<1]>=x) pos=query(l,mid,x,rt<<1);
else pos=query(mid+1,r,x,rt<<1|1);
maxn[rt]=max(maxn[rt<<1],maxn[rt<<1|1]);
return pos;
}
int main(){
int n;
while(scanf("%d%d%d",&h,&w,&n)!=EOF){
h=min(h,n);
build(1,h,1);
int x;
while(n--){
scanf("%d",&x);
if(maxn[1]<x) printf("-1\n");
else printf("%d\n",query(1,h,x,1));
}
}
return 0;
}
这题自己想了好久才写出来。。。果然模型的建立是核心。
hdu 2795 Billboard 线段树 单点更新
最新推荐文章于 2020-07-07 19:40:15 发布