标签:
问题描述
输入
输出
样例输入
3 5 5 2 4 3 3 3
样例输出
1 2 1 3 -1
把每一行都当成一个节点,比如第一行就是(1,1)这个点,第i行就用(i,i)表示,其中的值就是剩余可以贴海报的长度。
需要注意的是因为海波数量n最大可取200000,所以即便是海报一个一行,最多也就200000行,所以线段树只需开4*200000即可。
#include <iostream>
#include <stdio.h>
using namespace std;
const int MAXX=200005;
int w,h,n,ans;
struct node
{
int x,y,k;
}no[4*MAXX];
void build(int rt,int l,int r)
{
int mid=(l+r)>>1;
no[rt].x=l;
no[rt].y=r;
no[rt].k=w;
if(l==r)
return ;
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
}
void updata(int rt,int k)
{
if(no[rt].x==no[rt].y)
{
no[rt].k-=k;
ans= no[rt].x;
return ;
}
else
{
if(no[rt<<1].k>=k)
updata(rt<<1,k);
else
updata(rt<<1|1,k);
}
no[rt].k=max(no[rt<<1].k,no[rt<<1|1].k);
return ;
}
int main()
{
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
if(h>MAXX)
h=MAXX;
build(1,1,h);
for(int i=0;i<n;i++)
{
int ka;
ans=0;
scanf("%d",&ka);
if(no[1].k<ka)
printf("-1\n");
else
{updata(1,ka);
printf("%d\n",ans);
}
}
}
}标签:
原文地址:http://blog.csdn.net/qq_31237061/article/details/51345586