#include<stdio.h>
#define N 200005
int h,w,n;
struct
node {
int
x,y,max;
}
a[N*3];
int
mmax(int e,int f) {
return
e>f?e:f;
}
void
creattree(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].max=w;
if(
x==y)
return ;
int
temp=t*2;
int
mid=(x+y)/2;
creattree(temp,x,mid);
creattree(temp+1,mid+1,y);
}
int
find(int t,int k) {
if(
a[t].x==a[t].y) {
a[t].max-=k;
return
a[t].x;
}int
ans;
int
temp=t*2;
int
mid=(a[t].x+a[t].y)/2;
if(
a[temp].max>=k)
ans=find(temp,k);
else

ans=find(temp+1,k);
a[t].max=mmax(a[temp].max,a[temp+1].max);
return
ans;
}
int main() {
int
k;
while(
scanf("%d%d%d",&h,&w,&n)!=EOF) {
if(
h<n)//important
creattree(1,1,h);//important
else creattree(1,1,n);//important
while(n--) {
scanf("%d",&k);
if(
a[1].max<k)
printf("-1\n");
else

printf("%d\n",find(1,k));
} }
return
0;
}

hdu 2795线段树的更多相关文章

  1. hdu 2795 线段树(纵向)

    注意h的范围和n的范围,纵向建立线段树 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子思路:每次找到最大值的位子,然后减去L线段树功能:query:区间求最大值的位子(直接 ...

  2. hdu 2795 线段树(二维问题一维化)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 2795 线段树单点更新

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU 2795 线段树区间最大值,单点更新+二分

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu 2795 线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 #include <cstdio> #include <cmath> # ...

  6. HDU 2795 (线段树 单点更新) Billboard

    h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子. 每次找能放纸条而且是最上面的位置,询问完以后可以同时更新,所以可以把update和query写在同一个函数里. #include ...

  7. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  8. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

随机推荐

  1. P1597 语句解析

    题目背景 木有背景…… 题目描述 一串(<255)PASCAL语言,只有a,b,c 3个变量,而且只有赋值语句,赋值只能是一个一位的数字或一个变量,未赋值的变量值为0.输出a,b,c 最终的值. ...

  2. P2667 超级质数

    https://www.luogu.org/problem/show?pid=2667 题目背景 背景就是描述,描述就是背景...... 题目描述 一个质数如果从个位开始,依次去掉一位数字,两位数字, ...

  3. AJPFX简述Context.startService()和Context.bindService

    Context.startService()和Context.bindService 服务不能自己运行,需要通过调用Context.startService()或Context.bindService ...

  4. AJPFX总结面向对象(this和super的区别和应用)

    面向对象(this和super的区别和应用)(掌握)* A:this和super都代表什么        * this:代表当前对象的引用,谁来调用我,我就代表谁        * super:代表当 ...

  5. Performance engineering introduction

    1.Performance Software performance is one of software quality attributes,  it  equal to efficiency w ...

  6. configure: error: MySQL library not found

    在CentOS系统中,安装zabbix进行configure时会遇到以下问题 ./configure --enable-server --enable-agent --with-mysql --wit ...

  7. mac及windows下安装ss实现***

    官网下载shadowsock(mac/windows都是下面地址,页面会根据当前系统自动判断所下载的包) https://sourceforge.net/projects/shadowsocksgui ...

  8. qt5.5.1+vs2010发送邮件

    最近用到了这个功能,用于验证登陆~为此在网上找了好久,发现这方面的问答并不多!唯独这篇的解答实在.原文传送 1.首先选定自己的发送方的邮箱,无论是163还是qq邮箱等,首先都得开通SMTP服务:以16 ...

  9. ElasticSearch使用spring-data-elasticSearch的用法

    spring-data-Elasticsearch 使用之前,必须先确定版本,elasticsearch 对版本的要求比较高. spring和elasticsearch有两种链接方式,一种是用TCP协 ...

  10. 关于Java多线程(JAVA多线程实现的四种方式)

    Java多线程实现方式主要有四种:继承Thread类.实现Runnable接口.实现Callable接口通过FutureTask包装器来创建Thread线程.使用ExecutorService.Cal ...