HDU 2795 Billboard(线段树)
2015-08-07 23:48
375 查看
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=2795
#include<cstdio> #include<iostream> #include<sstream> #include<cstdlib> #include<cstring> #include<string> #include<climits> #include<cmath> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<set> #include<map> using namespace std; #define lson l, m , rt << 1 #define rson m+1, r, rt << 1 | 1 #define root 1,h,1 const int MX=200000+5; int S[MX<<2]; int h,w,n; void push_up(int rt) { S[rt]=max(S[rt<<1],S[rt<<1|1]); } void build(int l,int r,int rt) { S[rt]=w; if(l==r) return ; int m=(l+r)>>1; build(lson); build(rson); } int query(int x,int l,int r,int rt)//update函数合并于query函数里 { if(l==r) { S[rt]-=x; return l; } int m=(l+r)>>1,ret; if(S[rt<<1]>=x) ret=query(x,lson); else ret=query(x,rson); push_up(rt); return ret; } int main() { while(~scanf("%d%d%d",&h,&w,&n)) { if(h>n) h=n;//注意这里有限制,如果h<=n,节点为1到h,如果h>n,则应为1到n build(root); while(n--) { int x; scanf("%d",&x); if(S[1]<x) printf("-1\n"); else printf("%d\n",query(x,root)); } } return 0; }
相关文章推荐
- 3Sum
- CryEngine3教程合辑
- Elasticsearch性能测试
- hahahaha
- iOS 枚举加位操作
- ACM 计算几何模板 点在三角形内 加强版 HDU4380
- TCP/IP详解学习笔记--TCP数据流
- PAT 1029. Median (25)
- jquey操作select
- HTML学习笔记(3)——CSS的引入,选择器和文本样式
- 添加Hyper-V群集主机到VMM服务器
- CSS字体设置
- Hive 之再认识
- playsms+kannel 配置过程中常见错误总结(1)
- JavaScript 编程
- C语言函数-指针
- unity代码反混淆
- 不见面的情侣要做到的七件事
- VMM服务器主机和主机组介绍
- AutoCAD常用快捷键