这个题想到怎么建树就简单了,叶子节点为“一层”,树的大小最大200000就行了,因为最多就每个贴一层
#include<stdio.h>
#include<string.h>
#define MAXN 200005
struct node
{
int l,r;
int max;
int lmax,rmax;
}t[MAXN*4];
int h,w;
int max(int a,int b) {return a>b?a:b;}
int min(int a,int b) {return a<b?a:b;}
void construct(int l,int r,int p)
{
t[p].l=l,t[p].r=r;
if(l==r)
{
t[p].max=w;
t[p].lmax=t[p].rmax=0;
return ;
}
int m=(l+r)>>1;
construct(l,m,p<<1);
construct(m+1,r,p<<1|1);
t[p].lmax=t[p<<1].max;
t[p].rmax=t[p<<1|1].max;
t[p].max=max(t[p<<1].max,t[p<<1|1].max);
}
int ans;
void modify(int x,int p)
{
if(t[p].max<x)
{
ans=-1;
return ;
}
if(t[p].l==t[p].r)
{
t[p].max-=x;
ans=t[p].l;
return ;
}
if(x<=t[p].lmax) modify(x,p<<1);
else modify(x,p<<1|1);
t[p].lmax=t[p<<1].max;
t[p].rmax=t[p<<1|1].max;
t[p].max=max(t[p<<1].max,t[p<<1|1].max);
}
int main()
{
int n,x;
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
ans=1;
construct(1,min(h,n),1);
while(n--)
{
scanf("%d",&x);
modify(x,1);
printf("%d\n",ans);
}
}
return 0;
}